コード例 #1
0
        public void InitializePuzzlePieces()
        {
            unUsedPieces = new Dictionary <string, IPentominoePuzzlePiece>();
            ConcretePuzzlePieceFactory puzzlePieceFactory = new ConcretePuzzlePieceFactory();

            IPentominoePuzzlePiece piece = puzzlePieceFactory.CreatePuzzlePiece("X");

            unUsedPieces.Add(piece.pieceName(), piece);

            piece = puzzlePieceFactory.CreatePuzzlePiece("I");
            unUsedPieces.Add(piece.pieceName(), piece);

            piece = puzzlePieceFactory.CreatePuzzlePiece("T");
            unUsedPieces.Add(piece.pieceName(), piece);

            /*
             * unUsedPieces.Add(new PentominoePuzzlePiece("F"));
             *
             * unUsedPieces.Add(new PentominoePuzzlePiece("L"));
             * unUsedPieces.Add(new PentominoePuzzlePiece("N"));
             * unUsedPieces.Add(new PentominoePuzzlePiece("P"));
             * unUsedPieces.Add(new PentominoePuzzlePiece("T"));
             * unUsedPieces.Add(new PentominoePuzzlePiece("U"));
             * unUsedPieces.Add(new PentominoePuzzlePiece("V"));
             * unUsedPieces.Add(new PentominoePuzzlePiece("W"));
             * unUsedPieces.Add(new PentominoePuzzlePiece("Y"));
             * unUsedPieces.Add(new PentominoePuzzlePiece("Z"));
             */
        }
コード例 #2
0
ファイル: UnitTest1.cs プロジェクト: hksmile/PentominoeGame
        public void PlacePieceTInBounds()
        {
            PentominoeGameBoard    board = new PentominoeGameBoard();
            IPentominoePuzzlePiece piece = board.ChoosePiece("T");
            bool ret = board.PlacePiece(piece, 8, 2);

            Assert.IsTrue(ret);
        }
コード例 #3
0
ファイル: UnitTest1.cs プロジェクト: hksmile/PentominoeGame
        public void PlacePieceIOutOfBounds()
        {
            PentominoeGameBoard    board = new PentominoeGameBoard();
            IPentominoePuzzlePiece piece = board.ChoosePiece("I");
            bool ret = board.PlacePiece(piece, 0, 0);

            Assert.IsTrue(!ret);
        }
コード例 #4
0
        //TODO.. needs to ignore units already placed. need additional param
        private bool DoesUnitPieceCoverLocation(IPentominoePuzzlePiece piece, int unitNumber, int xIndex, int yIndex, HashSet <int> unitsPlaced)
        {
            PentominoeGameBoardLocation location;

            if (unitsPlaced != null && unitsPlaced.Count == 5)
            {
                return(true);
            }

            //ensure x,y locaiton on the game board and not covered.
            if (xIndex < 0 || yIndex < 0 || xIndex >= boardWidth || yIndex >= boardHeight)
            {
                Trace.WriteLine(piece.pieceName() + " unit " + unitNumber + "DOES NOT fit at location " + xIndex + " , " + yIndex + "OUT OF BOUNDS");
                return(false);
            }
            location = gameBoard[xIndex, yIndex];
            if (location.Covered)
            {
                Trace.WriteLine(piece.pieceName() + " unit " + unitNumber + "DOES NOT fit at location " + xIndex + " , " + yIndex + "ALREADY COVERED");
                return(false);
            }

            if (unitsPlaced == null)
            {
                unitsPlaced = new HashSet <int>();
            }
            unitsPlaced.Add(unitNumber);


            bool ret = true;

            PentominoePuzzleUnit unitSquare = piece.getUnits()[unitNumber];

            foreach (AdjacentLocation loc in unitSquare.adjacentLocations)
            {
                if (loc.Covered && !unitsPlaced.Contains(loc.UnitNumber)) //not every adjacent location is covered
                {
                    ret = DoesUnitPieceCoverLocation(piece, loc.UnitNumber, xIndex + loc.Xoffset, yIndex + loc.Yoffset, unitsPlaced);
                    if (!ret)
                    {
                        break;
                    }
                }
            }
            Trace.WriteLine(piece.pieceName() + " unit " + unitNumber + " fits " + ret + " at location " + xIndex + " , " + yIndex);

            return(ret);
        }
コード例 #5
0
 public bool PlacePiece(IPentominoePuzzlePiece piece, int xIndex, int yIndex)
 {
     return(DoesUnitPieceCoverLocation(piece, 0, xIndex, yIndex, null));
 }