Ejemplo n.º 1
0
        public static VERDICT TickMoved(int row, int col)
        {
            STATE_CELL cur_state = GameArea[row, col];

            if (cur_state == STATE_CELL.EMPTY)
            {
                GameArea[row, col] = STATE_CELL.TIC;
                NextTurn();
                return(DetermineVerdict(row, col));
            }
            else
            {
                return(VERDICT.ERROR);
            }
        }
Ejemplo n.º 2
0
        private static VERDICT DetermineVerdict(int row, int col)
        {
            STATE_CELL cur_state = GameArea[row, col];

            if (row == 0 && col == 0)
            {
                if (GameArea[0, 1] == cur_state && GameArea[0, 2] == cur_state ||
                    GameArea[1, 0] == cur_state && GameArea[2, 0] == cur_state ||
                    GameArea[1, 1] == cur_state && GameArea[2, 2] == cur_state)
                {
                    if (cur_state == STATE_CELL.TIC)
                    {
                        return(VERDICT.TIC_WINS);
                    }

                    return(VERDICT.TOE_WINS);
                }
            }

            if (row == 0 && col == 1)
            {
                if (GameArea[0, 0] == cur_state && GameArea[0, 2] == cur_state ||
                    GameArea[1, 1] == cur_state && GameArea[2, 1] == cur_state)
                {
                    if (cur_state == STATE_CELL.TIC)
                    {
                        return(VERDICT.TIC_WINS);
                    }

                    return(VERDICT.TOE_WINS);
                }
            }

            if (row == 0 && col == 2)
            {
                if (GameArea[0, 0] == cur_state && GameArea[0, 1] == cur_state ||
                    GameArea[1, 2] == cur_state && GameArea[2, 2] == cur_state ||
                    GameArea[1, 1] == cur_state && GameArea[2, 0] == cur_state)
                {
                    if (cur_state == STATE_CELL.TIC)
                    {
                        return(VERDICT.TIC_WINS);
                    }

                    return(VERDICT.TOE_WINS);
                }
            }

            if (row == 1 && col == 0)
            {
                if (GameArea[0, 0] == cur_state && GameArea[2, 0] == cur_state ||
                    GameArea[1, 1] == cur_state && GameArea[1, 2] == cur_state)
                {
                    if (cur_state == STATE_CELL.TIC)
                    {
                        return(VERDICT.TIC_WINS);
                    }

                    return(VERDICT.TOE_WINS);
                }
            }

            if (row == 1 && col == 1)
            {
                if (GameArea[0, 0] == cur_state && GameArea[2, 2] == cur_state ||
                    GameArea[0, 2] == cur_state && GameArea[2, 0] == cur_state ||
                    GameArea[0, 1] == cur_state && GameArea[2, 1] == cur_state ||
                    GameArea[1, 0] == cur_state && GameArea[1, 2] == cur_state)
                {
                    if (cur_state == STATE_CELL.TIC)
                    {
                        return(VERDICT.TIC_WINS);
                    }

                    return(VERDICT.TOE_WINS);
                }
            }

            if (row == 1 && col == 2)
            {
                if (GameArea[0, 2] == cur_state && GameArea[2, 2] == cur_state ||
                    GameArea[1, 1] == cur_state && GameArea[1, 0] == cur_state)
                {
                    if (cur_state == STATE_CELL.TIC)
                    {
                        return(VERDICT.TIC_WINS);
                    }

                    return(VERDICT.TOE_WINS);
                }
            }

            if (row == 2 && col == 0)
            {
                if (GameArea[0, 0] == cur_state && GameArea[1, 0] == cur_state ||
                    GameArea[2, 1] == cur_state && GameArea[2, 2] == cur_state ||
                    GameArea[1, 1] == cur_state && GameArea[0, 2] == cur_state)
                {
                    if (cur_state == STATE_CELL.TIC)
                    {
                        return(VERDICT.TIC_WINS);
                    }

                    return(VERDICT.TOE_WINS);
                }
            }

            if (row == 2 && col == 1)
            {
                if (GameArea[1, 1] == cur_state && GameArea[0, 1] == cur_state ||
                    GameArea[2, 0] == cur_state && GameArea[2, 2] == cur_state)
                {
                    if (cur_state == STATE_CELL.TIC)
                    {
                        return(VERDICT.TIC_WINS);
                    }

                    return(VERDICT.TOE_WINS);
                }
            }

            if (row == 2 && col == 2)
            {
                if (GameArea[2, 1] == cur_state && GameArea[2, 0] == cur_state ||
                    GameArea[1, 2] == cur_state && GameArea[0, 2] == cur_state ||
                    GameArea[1, 1] == cur_state && GameArea[0, 0] == cur_state)
                {
                    if (cur_state == STATE_CELL.TIC)
                    {
                        return(VERDICT.TIC_WINS);
                    }

                    return(VERDICT.TOE_WINS);
                }
            }

            if (num_turn < MAX_TURN)
            {
                return(VERDICT.CONTINUE);
            }

            return(VERDICT.DRAW);
        }