/* Copyright (C) 2007 Andre Seidelt, All Rights Reserved. This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* * this class describes a number of steps that let to the current layout. */ class Tail { // the parts that let to the current layout int[] lastParts; // create new from old tail and a new piece public Tail(Tail lastTail, int type) { lastParts = new int[2]; if(lastTail != null) { lastParts[1] = lastTail.lastParts[0]; } lastParts[0] = type; } // check if adding the given piece is allowed or if it would // lead to a dead-end boolean isAllowed(int type) { return isAllowed(1, 2, 4, type) && isAllowed(2, 4, 3, type) && isAllowed(4, 3, 1, type) && isAllowed(3, 1, 2, type) && isAllowed(4, 2, 1, type) && isAllowed(2, 1, 3, type) && isAllowed(1, 3, 4, type) && isAllowed(3, 4, 2, type); } // compare-helper boolean isAllowed(int a, int b, int c, int type) { return !((type == a) && (lastParts[0] == b) && (lastParts[1] == c)); } }