Esempio n. 1
0
        public bool CheckVertical(Sign sign)
        {
            int vertical = 0;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (Map[j, i] == sign)
                    {
                        vertical++;
                    }
                }
                if (vertical == 3)
                {
                    return(true);
                }
                else
                {
                    vertical = 0;
                }
            }
            return(false);
        }
Esempio n. 2
0
        public bool CheckHorizontal(Sign x)
        {
            int horizontal = 0;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (Map[i, j] == x)
                    {
                        horizontal++;
                    }
                }
                if (horizontal == 3)
                {
                    return(true);
                }
                else
                {
                    horizontal = 0;
                }
            }
            return(false);
        }
Esempio n. 3
0
 public Field(Coord x, Coord y, Sign sign)
 {
     X    = x;
     Y    = y;
     Sign = sign;
 }
Esempio n. 4
0
 public bool CheckBottomLeftToTopRightDiagonal(Sign sign)
 {
     return((Map[2, 0] == sign) && (Map[1, 1] == sign) && (Map[0, 2] == sign));
 }
Esempio n. 5
0
 public bool CheckDiagonals(Sign sign)
 {
     return(CheckTopLeftToBottomRightDiagonal(sign) || CheckBottomLeftToTopRightDiagonal(sign));
 }
Esempio n. 6
0
 public bool CheckTopLeftToBottomRightDiagonal(Sign sign)
 {
     return((Map[0, 0] == sign) && (Map[1, 1] == sign) && (Map[2, 2] == sign));
 }
        public int Minimax(List <Block> blocks, Sign currentPlayer, Sign oppositePlayer, int alpha, int beta, bool isMax, int currentPlay)
        {
            int score = EvaluateBoard(blocks, currentPlayer, oppositePlayer, currentPlay);

            if (score == 10 - currentPlay)
            {
                return(10 - currentPlay);
            }

            if (score == -10 + currentPlay)
            {
                return(-10 + currentPlay);
            }

            if (!IsEmptyBlock(blocks))
            {
                return(0);
            }

            if (isMax)
            {
                int best = MIN;

                for (int i = 0; i < blocks.Count; i++)
                {
                    if (blocks[i].sign == Sign.Empty)
                    {
                        blocks[i].sign = currentPlayer;

                        currentPlay++;
                        int value = Minimax(blocks, currentPlayer, oppositePlayer, alpha, beta, !isMax, currentPlay);

                        blocks[i].sign = Sign.Empty;

                        best = Mathf.Max(best, value);

                        alpha = Math.Max(alpha, best);

                        if (beta <= alpha)
                        {
                            break;
                        }
                    }
                }

                return(best);
            }
            else
            {
                int best = MAX;

                for (int i = 0; i < blocks.Count; i++)
                {
                    if (blocks[i].sign == Sign.Empty)
                    {
                        blocks[i].sign = oppositePlayer;

                        currentPlay++;
                        int value = Minimax(blocks, currentPlayer, oppositePlayer, alpha, beta, !isMax, currentPlay);


                        blocks[i].sign = Sign.Empty;

                        best = Math.Min(best, value);

                        beta = Math.Min(beta, best);

                        if (beta <= alpha)
                        {
                            break;
                        }
                    }
                }

                return(best);
            }
        }
Esempio n. 8
0
 public Bot(Sign sign) : base(sign)
 {
     _random = new Random();
 }
Esempio n. 9
0
 public HumanPlayer(Sign sign) : base(sign)
 {
 }
Esempio n. 10
0
 private void ToggleNextSign()
 => _nextSign = _nextSign == Sign.X ? Sign.O : Sign.X;
Esempio n. 11
0
 public TicTacToe()
 {
     _board        = new Board();
     _gameOverRule = new GameOverRule();
     _nextSign     = Sign.X;
 }