示例#1
0
        public void PlayerMove(int column)
        {
            var temp = (int[, ])board.Clone();

            for (int y = board.GetLength(1) - 1; y >= 0; y--)
            {
                if (temp[column, y] == 0)
                {
                    temp[column, y] = 1;
                    break;
                }
            }
            foreach (Fou fou in currFou.Moves)
            {
                if (temp.Rank == fou.Board.Rank &&
                    Enumerable.Range(0, temp.Rank).All(dimension => temp.GetLength(dimension) == fou.Board.GetLength(dimension) &&
                                                       temp.Cast <int>().SequenceEqual(fou.Board.Cast <int>())))
                {
                    board         = (int[, ])fou.Board.Clone();
                    currFou       = fou;
                    monte.Current = currFou;
                    return;
                }
            }
        }
示例#2
0
 public ConnectFour(bool playerStarts)
 {
     currFou       = new Fou(board, playerStarts, playerStarts);
     monte         = new MonteCarloer2();
     monte.Current = currFou;
     monte.MonteCarlo(currFou, playerStarts);
     isMax = false;
 }
示例#3
0
        static int CheckGameOver(Fou fou)
        {
            int count      = 0;
            int chainvalue = 1;

            for (int y = 0; y < fou.Board.GetLength(1); y++) //checking horizantal 4
            {
                for (int x = 0; x < fou.Board.GetLength(0); x++)
                {
                    if (fou.Board[x, y] != chainvalue)
                    {
                        count = 0;
                    }
                    count     += fou.Board[x, y];
                    chainvalue = fou.Board[x, y];

                    if (count >= 4)
                    {
                        return(0);
                    }
                    else if (count <= -4)
                    {
                        return(1);
                    }
                }
                count = 0;
            }

            for (int x = 0; x < fou.Board.GetLength(0); x++) //checking vertical 4
            {
                for (int y = 0; y < fou.Board.GetLength(1); y++)
                {
                    if (fou.Board[x, y] != chainvalue)
                    {
                        count = 0;
                    }
                    count     += fou.Board[x, y];
                    chainvalue = fou.Board[x, y];

                    if (count >= 4)
                    {
                        return(2);
                    }
                    else if (count <= -4)
                    {
                        return(3);
                    }
                }
                count = 0;
            }

            for (int x = 1; x < fou.Board.GetLength(0) - 2; x++) //left to right diagonal
            {
                count = 0;
                int row, col;
                for (col = x, row = 0; row < fou.Board.GetLength(1) && col < fou.Board.GetLength(0); row++, col++)
                {
                    if (fou.Board[col, row] != chainvalue)
                    {
                        count = 0;
                    }
                    count     += fou.Board[col, row];
                    chainvalue = fou.Board[col, row];
                    if (count >= 4)
                    {
                        return(4);
                    }
                    else if (count <= -4)
                    {
                        return(5);
                    }
                }
                count = 0;
            }
            for (int y = 0; y < fou.Board.GetLength(1) - 2; y++)
            {
                count = 0;
                int row, col;
                for (row = y, col = 0; row < fou.Board.GetLength(1) && col < fou.Board.GetLength(0); row++, col++)
                {
                    if (fou.Board[col, row] != chainvalue)
                    {
                        count = 0;
                    }
                    count     += fou.Board[col, row];
                    chainvalue = fou.Board[col, row];
                    if (count >= 4)
                    {
                        return(6);
                    }
                    else if (count <= -4)
                    {
                        return(7);
                    }
                }
                count = 0;
            }

            for (int y = 0; y < fou.Board.GetLength(1) - 2; y++) //right to left diagonal
            {
                count = 0;
                int row, col;
                for (row = y, col = fou.Board.GetLength(0) - 1; row < fou.Board.GetLength(1) && col >= 0; row++, col--)
                {
                    if (fou.Board[col, row] != chainvalue)
                    {
                        count = 0;
                    }
                    count     += fou.Board[col, row];
                    chainvalue = fou.Board[col, row];
                    if (count >= 4)
                    {
                        return(8);
                    }
                    else if (count <= -4)
                    {
                        return(9);
                    }
                }
                count = 0;
            }
            for (int x = fou.Board.GetLength(1) - 2; x > 2; x--)
            {
                count = 0;
                int row, col;
                for (row = 0, col = x; row < fou.Board.GetLength(1) && col >= 0; row++, col--)
                {
                    if (fou.Board[col, row] == 0)
                    {
                        count = 0;
                    }
                    else
                    {
                        count += fou.Board[col, row];
                    }
                    if (count >= 4)
                    {
                        return(10);
                    }
                    else if (count <= -4)
                    {
                        return(11);
                    }
                }
                count = 0;
            }

            bool isFull = true;

            for (int x = 0; x < fou.Board.GetLength(0); x++)
            {
                for (int y = 0; y < fou.Board.GetLength(1); y++)
                {
                    if (fou.Board[x, y] == 0)
                    {
                        isFull = false;
                    }
                }
            }
            if (isFull)
            {
                fou.IsTerminal = true;
                fou.Value      = 0.5;
                return(12);
            }
            return(13);
        }
示例#4
0
 public void CompMove()
 {
     currFou       = (Fou)monte.OptimalMove(isMax, 1000);
     monte.Current = currFou;
     board         = (int[, ])currFou.Board.Clone();
 }