Ejemplo n.º 1
0
        public BoardState(Board board)
        {
            this.a1 = new BoardSpace(board.a1);
            this.a2 = new BoardSpace(board.a2);
            this.a3 = new BoardSpace(board.a3);
            this.a4 = new BoardSpace(board.a4);
            this.a5 = new BoardSpace(board.a5);
            this.b1 = new BoardSpace(board.b1);
            this.b2 = new BoardSpace(board.b2);
            this.b3 = new BoardSpace(board.b3);
            this.b4 = new BoardSpace(board.b4);
            this.b5 = new BoardSpace(board.b5);
            this.c1 = new BoardSpace(board.c1);
            this.c2 = new BoardSpace(board.c2);
            this.c3 = new BoardSpace(board.c3);
            this.c4 = new BoardSpace(board.c4);
            this.c5 = new BoardSpace(board.c5);
            this.d1 = new BoardSpace(board.d1);
            this.d2 = new BoardSpace(board.d2);
            this.d3 = new BoardSpace(board.d3);
            this.d4 = new BoardSpace(board.d4);
            this.d5 = new BoardSpace(board.d5);
            this.e1 = new BoardSpace(board.e1);
            this.e2 = new BoardSpace(board.e2);
            this.e3 = new BoardSpace(board.e3);
            this.e4 = new BoardSpace(board.e4);
            this.e5 = new BoardSpace(board.e5);

            CollectAllAvailableSpaces();
            CreateAllWinningConditions();
        }
Ejemplo n.º 2
0
        private int EvaluateWin(List <BoardSpace> win, Owner currentPlayerOwner, Owner opponentPlayerOwner)
        {
            int        score       = 0;
            BoardSpace firstSpace  = win[0];
            BoardSpace secondSpace = win[1];
            BoardSpace thirdSpace  = win[2];
            BoardSpace fourthSpace = win[3];


            // firstSpace evaluation
            if (firstSpace.owner == currentPlayerOwner)
            {
                score = 1;
            }
            else if (firstSpace.owner == opponentPlayerOwner)
            {
                score = -1;
            }

            // secondSpace evaluation
            if (secondSpace.owner == currentPlayerOwner)
            {
                if (score == 1) //firstSpace is currentPlayer
                {
                    score = 10;
                }
                else if (score == -1)
                {
                    return(0);
                }
                else //firstSpace is empty
                {
                    score = 1;
                }
            }
            else if (secondSpace.owner == opponentPlayerOwner)
            {
                if (score == -1)
                {
                    score = -10;
                }
                else if (score == 1)
                {
                    return(0);
                }
                else
                {
                    score = -1;
                }
            }

            // thirdSpace evaluation
            if (thirdSpace.owner == currentPlayerOwner)
            {
                if (score > 0) //firstSpace or secondSpace is currentPlayer
                {
                    score *= 10;
                }
                else if (score < 0)
                {
                    return(0);
                }
                else //firstSpace is empty
                {
                    score = 1;
                }
            }
            else if (thirdSpace.owner == opponentPlayerOwner)
            {
                if (score < 0)
                {
                    score *= 10;
                }
                else if (score > 1)
                {
                    return(0);
                }
                else
                {
                    score = -1;
                }
            }

            // fourthSpace evaluation
            if (fourthSpace.owner == currentPlayerOwner)
            {
                if (score > 0) //firstSpace or secondSpace is currentPlayer
                {
                    score *= 10;
                }
                else if (score < 0)
                {
                    return(0);
                }
                else //firstSpace is empty
                {
                    score = 1;
                }
            }
            else if (fourthSpace.owner == opponentPlayerOwner)
            {
                if (score < 0)
                {
                    score *= 10;
                }
                else if (score > 1)
                {
                    return(0);
                }
                else
                {
                    score = -1;
                }
            }

            return(score);
        }