Exemple #1
0
        public List <Board> GenerateSafeBoards(bool includeCheckmates)
        {
            List <Board> boards       = this.GenerateSubBoards();
            Board        workingBoard = new Board();

            for (int k = 0; k < boards.Count; k++)
            {
                workingBoard.Copy(boards[k]);

                foreach (Board b in workingBoard.GenerateSubBoards())
                {
                    if (b.GetWinner() == workingBoard.CurrentPlayer)
                    {
                        boards.RemoveAt(k);
                        k--;
                        break;
                    }
                    if (includeCheckmates &&
                        BoardEvaluator.HasCheckmate(b, workingBoard.CurrentPlayer))
                    {
                        boards.RemoveAt(k);
                        k--;
                        break;
                    }
                }
            }
            return(boards);
        }
Exemple #2
0
        // Finds all unique boards possible after applying a move by the current player
        public List <Board> GenerateSubBoards()
        {
            Dictionary <Board, int> boards = new Dictionary <Board, int>(256);

            if (this.GetWinner() != PieceColor.Empty)
            {
                return(new List <Board>());
            }

            Board b = new Board(this);

            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    if (this.GetColorAt(i, j) == PieceColor.Empty)
                    {
                        b.Copy(this);
                        b.ApplyMoveFast(i, j, this.CurrentPlayer, Rotation.LowerLeftAntiClockwise);
                        if (!boards.ContainsKey(b))
                        {
                            b.Evaluation = BoardEvaluator.Evaluate(ref b);
                            boards.Add(new Board(b), 0);
                        }
                        b.Copy(this);
                        b.ApplyMoveFast(i, j, this.CurrentPlayer, Rotation.LowerLeftClockwise);
                        if (!boards.ContainsKey(b))
                        {
                            b.Evaluation = BoardEvaluator.Evaluate(ref b);
                            boards.Add(new Board(b), 0);
                        }
                        b.Copy(this);
                        b.ApplyMoveFast(i, j, this.CurrentPlayer, Rotation.LowerRightAntiClockwise);
                        if (!boards.ContainsKey(b))
                        {
                            b.Evaluation = BoardEvaluator.Evaluate(ref b);
                            boards.Add(new Board(b), 0);
                        }
                        b.Copy(this);
                        b.ApplyMoveFast(i, j, this.CurrentPlayer, Rotation.LowerRightClockwise);
                        if (!boards.ContainsKey(b))
                        {
                            b.Evaluation = BoardEvaluator.Evaluate(ref b);
                            boards.Add(new Board(b), 0);
                        }
                        b.Copy(this);
                        b.ApplyMoveFast(i, j, this.CurrentPlayer, Rotation.UpperLeftAntiClockwise);
                        if (!boards.ContainsKey(b))
                        {
                            b.Evaluation = BoardEvaluator.Evaluate(ref b);
                            boards.Add(new Board(b), 0);
                        }
                        b.Copy(this);
                        b.ApplyMoveFast(i, j, this.CurrentPlayer, Rotation.UpperLeftClockwise);
                        if (!boards.ContainsKey(b))
                        {
                            b.Evaluation = BoardEvaluator.Evaluate(ref b);
                            boards.Add(new Board(b), 0);
                        }
                        b.Copy(this);
                        b.ApplyMoveFast(i, j, this.CurrentPlayer, Rotation.UpperRightAntiClockwise);
                        if (!boards.ContainsKey(b))
                        {
                            b.Evaluation = BoardEvaluator.Evaluate(ref b);
                            boards.Add(new Board(b), 0);
                        }
                        b.Copy(this);
                        b.ApplyMoveFast(i, j, this.CurrentPlayer, Rotation.UpperRightClockwise);
                        if (!boards.ContainsKey(b))
                        {
                            b.Evaluation = BoardEvaluator.Evaluate(ref b);
                            boards.Add(new Board(b), 0);
                        }
                    }
                }
            }

            return(new List <Board>(boards.Keys));
        }
Exemple #3
0
        // Finds all unique boards possible after applying a move by the current player
        public List<Board> GenerateSubBoards()
        {
            Dictionary<Board, int> boards = new Dictionary<Board, int>(256);

            if (this.GetWinner() != PieceColor.Empty)
                return new List<Board>();

            Board b = new Board(this);

            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    if (this.GetColorAt(i, j) == PieceColor.Empty)
                    {
                        b.Copy(this);
                        b.ApplyMoveFast(i, j, this.CurrentPlayer, Rotation.LowerLeftAntiClockwise);
                        if (!boards.ContainsKey(b))
                        {
                            b.Evaluation = BoardEvaluator.Evaluate(ref b);
                            boards.Add(new Board(b), 0);
                        }
                        b.Copy(this);
                        b.ApplyMoveFast(i, j, this.CurrentPlayer, Rotation.LowerLeftClockwise);
                        if (!boards.ContainsKey(b))
                        {
                            b.Evaluation = BoardEvaluator.Evaluate(ref b);
                            boards.Add(new Board(b), 0);
                        }
                        b.Copy(this);
                        b.ApplyMoveFast(i, j, this.CurrentPlayer, Rotation.LowerRightAntiClockwise);
                        if (!boards.ContainsKey(b))
                        {
                            b.Evaluation = BoardEvaluator.Evaluate(ref b);
                            boards.Add(new Board(b), 0);
                        }
                        b.Copy(this);
                        b.ApplyMoveFast(i, j, this.CurrentPlayer, Rotation.LowerRightClockwise);
                        if (!boards.ContainsKey(b))
                        {
                            b.Evaluation = BoardEvaluator.Evaluate(ref b);
                            boards.Add(new Board(b), 0);
                        }
                        b.Copy(this);
                        b.ApplyMoveFast(i, j, this.CurrentPlayer, Rotation.UpperLeftAntiClockwise);
                        if (!boards.ContainsKey(b))
                        {
                            b.Evaluation = BoardEvaluator.Evaluate(ref b);
                            boards.Add(new Board(b), 0);
                        }
                        b.Copy(this);
                        b.ApplyMoveFast(i, j, this.CurrentPlayer, Rotation.UpperLeftClockwise);
                        if (!boards.ContainsKey(b))
                        {
                            b.Evaluation = BoardEvaluator.Evaluate(ref b);
                            boards.Add(new Board(b), 0);
                        }
                        b.Copy(this);
                        b.ApplyMoveFast(i, j, this.CurrentPlayer, Rotation.UpperRightAntiClockwise);
                        if (!boards.ContainsKey(b))
                        {
                            b.Evaluation = BoardEvaluator.Evaluate(ref b);
                            boards.Add(new Board(b), 0);
                        }
                        b.Copy(this);
                        b.ApplyMoveFast(i, j, this.CurrentPlayer, Rotation.UpperRightClockwise);
                        if (!boards.ContainsKey(b))
                        {
                            b.Evaluation = BoardEvaluator.Evaluate(ref b);
                            boards.Add(new Board(b), 0);
                        }
                    }
                }
            }

            return new List<Board>(boards.Keys);
        }
Exemple #4
0
        private Move GetMoveFromBoards(Board currentBoard, Board aiBoard)
        {
            Move returnMove = new Move();
            if (currentBoard.Equals(aiBoard))
            {
                returnMove.pieceColor = PieceColor.Empty;
                return returnMove;
            }

            PieceColor moveColor = (aiBoard.CurrentPlayer == PieceColor.White) ? PieceColor.Black: PieceColor.White;

            returnMove.pieceColor = moveColor;

            Board b = new Board(currentBoard);

            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    b.Copy(currentBoard);
                    if (b.GetColorAt(i, j) == PieceColor.Empty)
                    {
                        returnMove.xCoord = i;
                        returnMove.yCoord = j;

                        b.Copy(currentBoard);
                        b.PlacePieceAt(i, j, moveColor);
                        b.DoRotation(Rotation.LowerLeftAntiClockwise);
                        if (b.Equals(aiBoard))
                        {
                            returnMove.rotation = Rotation.LowerLeftAntiClockwise;
                            return returnMove;
                        }

                        b.Copy(currentBoard);
                        b.PlacePieceAt(i, j, moveColor);
                        b.DoRotation(Rotation.LowerLeftClockwise);
                        if (b.Equals(aiBoard))
                        {
                            returnMove.rotation = Rotation.LowerLeftClockwise;
                            return returnMove;
                        }

                        b.Copy(currentBoard);
                        b.PlacePieceAt(i, j, moveColor);
                        b.DoRotation(Rotation.LowerRightAntiClockwise);
                        if (b.Equals(aiBoard))
                        {
                            returnMove.rotation = Rotation.LowerRightAntiClockwise;
                            return returnMove;
                        }

                        b.Copy(currentBoard);
                        b.PlacePieceAt(i, j, moveColor);
                        b.DoRotation(Rotation.LowerRightClockwise);
                        if (b.Equals(aiBoard))
                        {
                            returnMove.rotation = Rotation.LowerRightClockwise;
                            return returnMove;
                        }

                        b.Copy(currentBoard);
                        b.PlacePieceAt(i, j, moveColor);
                        b.DoRotation(Rotation.UpperLeftAntiClockwise);
                        if (b.Equals(aiBoard))
                        {
                            returnMove.rotation = Rotation.UpperLeftAntiClockwise;
                            return returnMove;
                        }

                        b.Copy(currentBoard);
                        b.PlacePieceAt(i, j, moveColor);
                        b.DoRotation(Rotation.UpperLeftClockwise);
                        if (b.Equals(aiBoard))
                        {
                            returnMove.rotation = Rotation.UpperLeftClockwise;
                            return returnMove;
                        }

                        b.Copy(currentBoard);
                        b.PlacePieceAt(i, j, moveColor);
                        b.DoRotation(Rotation.UpperRightAntiClockwise);
                        if (b.Equals(aiBoard))
                        {
                            returnMove.rotation = Rotation.UpperRightAntiClockwise;
                            return returnMove;
                        }

                        b.Copy(currentBoard);
                        b.PlacePieceAt(i, j, moveColor);
                        b.DoRotation(Rotation.UpperRightClockwise);
                        if (b.Equals(aiBoard))
                        {
                            returnMove.rotation = Rotation.UpperRightClockwise;
                            return returnMove;
                        }
                    }
                }
            }
            // shouldn't ever get here
            Debug.Assert(false, "Bogus move \r\n" + masterBoard.ToString());
            return returnMove;
        }
Exemple #5
0
        public List<Board> GenerateSafeBoards(bool includeCheckmates)
        {
            List<Board> boards = this.GenerateSubBoards();
            Board workingBoard = new Board();

            for (int k = 0; k < boards.Count; k++)
            {
                workingBoard.Copy(boards[k]);

                foreach (Board b in workingBoard.GenerateSubBoards())
                {
                    if (b.GetWinner() == workingBoard.CurrentPlayer)
                    {
                        boards.RemoveAt(k);
                        k--;
                        break;
                    }
                    if(includeCheckmates &&
                        BoardEvaluator.HasCheckmate(b, workingBoard.CurrentPlayer))
                    {
                        boards.RemoveAt(k);
                        k--;
                        break;
                    }
                }
            }
            return boards;
        }