public Point TakeTurn(Mark[,] gameField)
        {
            Dictionary <double, Point>       options  = new Dictionary <double, Point>();
            Dictionary <double, List <int> > summarys = new Dictionary <double, List <int> >();

            for (int i = 0; i < gameField.GetLength(0); i++)
            {
                for (int j = 0; j < gameField.GetLength(1); j++)
                {
                    if (gameField[i, j] == Mark.Blank)
                    {
                        Mark[,] option = (Mark[, ])gameField.Clone();
                        option[i, j]   = InstanceRole;
                        (List <int> features, double evaluation) = Summarize(option);
                        if (!options.Keys.Contains(evaluation))
                        {
                            options.Add(evaluation, new Point(j, i));
                            summarys.Add(evaluation, features);
                        }
                    }
                }
            }

            KeyValuePair <double, Point> pair = options.Where(p => p.Key == options.Keys.Max()).ToList()[0];

            _history.Add(new KeyValuePair <double, List <int> >(pair.Key, summarys[pair.Key]));
            return(pair.Value);
        }
Ejemplo n.º 2
0
        //Перебор всех ходов
        static GameResult GetGameResult(Mark[,] field)
        {
            bool crossWin  = false;
            bool circleWin = false;

            for (int i = 0; i < WinSequence; i++)
            {
                for (int j = 0; j < WinSequence; j++)
                {
                    if (!crossWin)
                    {
                        crossWin = Winner(i, j, Mark.Cross, field);
                    }
                    if (!circleWin)
                    {
                        circleWin = Winner(i, j, Mark.Circle, field);
                    }
                }
            }
            if (crossWin && !circleWin)
            {
                return(GameResult.CrossWin);
            }
            if (!crossWin && circleWin)
            {
                return(GameResult.CircleWin);
            }
            return(GameResult.Draw);
        }
Ejemplo n.º 3
0
        public static bool CheckDiagonal(Mark[,] field, Mark mark)
        {
            int winMark = 0;

            for (int i = 0; i < 3; i++)
            {
                if (field[i, i] != mark)
                {
                    break;
                }
                else
                {
                    winMark++;
                }
            }
            if (winMark >= 3)
            {
                return(true);
            }
            winMark = 0;
            for (int i = 0; i < 3; i++)
            {
                if (field[2 - i, i] != mark)
                {
                    break;
                }
                else
                {
                    winMark++;
                }
            }
            return(winMark >= 3);
        }
Ejemplo n.º 4
0
 public static bool HasWinSequence(Mark[,] field, Mark mark)
 {
     for (int y = 0; y < 3; y++)
     {
         if (field[0, y] == mark && field[1, y] == mark && field[2, y] == mark)
         {
             return(true);
         }
         if (field[y, 0] == mark && field[y, 1] == mark && field[y, 2] == mark)
         {
             return(true);
         }
     }
     if (field[1, 1] == mark)
     {
         if (field[0, 0] == mark && field[2, 2] == mark)
         {
             return(true);
         }
         if (field[2, 0] == mark && field[0, 2] == mark)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 5
0
        static bool HasWinSequence(Mark[,] field, Mark mark)
        {
            int[][] combinations =
            {
                new int[] { 1, 2, 3 },
                new int[] { 4, 5, 6 },
                new int[] { 7, 8, 9 },
                new int[] { 1, 4, 7 },
                new int[] { 2, 5, 8 },
                new int[] { 3, 6, 9 },
                new int[] { 1, 5, 9 },
                new int[] { 3, 5, 7 }
            };

            var marksByIndex = GetMarksWithIndexes(field);

            for (int i = 0; i < combinations.Length; i++)
            {
                if (marksByIndex[combinations[i][0] - 1] == mark &&
                    marksByIndex[combinations[i][1] - 1] == mark &&
                    marksByIndex[combinations[i][2] - 1] == mark)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 6
0
 public static bool IscomboByMark(Mark [,] field, int i, Mark mark)
 {
     return((field[i, 0] == field[i, 1] && field[i, 1] == field[i, 2] && field[i, 2] == mark) ||
            (field[0, i] == field[1, i] && field[1, i] == field[2, i] && field[2, i] == mark) ||
            (field[0, 0] == field[1, 1] && field[1, 1] == field[2, 2] && field[2, 2] == mark) ||
            (field[0, 2] == field[1, 1] && field[1, 1] == field[2, 0] && field[2, 0] == mark));
 }
Ejemplo n.º 7
0
 // Constructor. Perform any necessary data initialisation here.
 // Uncomment the optional parameters if attempting the stretch goal -- keep the default values to avoid breaking unit tests.
 public OxoBoard(int width = 3, int height = 3, int inARow = 3)
 {
     BoardWidth  = width;
     BoardHeight = height;
     Board       = new Mark[BoardWidth, BoardHeight];
     InARow      = inARow;
 }
Ejemplo n.º 8
0
 public static GameResult GetGameResult(Mark[,] field)
 {
     HasWinSequence(new[] { field[0, 0], field[0, 1], field[0, 2] });
     HasWinSequence(new[] { field[1, 0], field[1, 1], field[1, 2] });
     HasWinSequence(new[] { field[2, 0], field[2, 1], field[2, 2] });
     HasWinSequence(new[] { field[0, 0], field[1, 0], field[2, 0] });
     return(GameResult.CrossWin);
 }
Ejemplo n.º 9
0
 // Constructor. Perform any necessary data initialisation here.
 // Uncomment the optional parameters if attempting the stretch goal -- keep the default values to avoid breaking unit tests.
 public OxoBoard(/* int width = 3, int height = 3, int inARow = 3 */)
 {
     Board = new Mark[3, 3] {
         { 0, 0, 0 },
         { 0, 0, 0 },
         { 0, 0, 0 }
     };
 }
Ejemplo n.º 10
0
    private void Awake()
    {
        _board        = new Mark[3, 3];
        _localPlayers = new List <Mark>();

        OnSpotSelected          += HandleSpotSelected;
        GameManager.OnStartGame += HandleStartGame;
    }
Ejemplo n.º 11
0
 public Generator(int w, int h, Options ops)
 {
     graph      = new Graph(new IntVector2(5, 5));
     grid       = new Mark[w, h];
     dimensions = new IntVector2(w, h);
     rooms      = new List <Room>();
     options    = ops;
     rng        = new Random();
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Констуктор новой игры
 /// </summary>
 /// <param name="canvasSizeX">Размер холста для рисования по горизонтали</param>
 /// <param name="canvasSizeY">Размер холста для рисования по вертикали</param>
 /// <param name="rows">Количество строк</param>
 /// <param name="cols">Количество столбцов</param>
 public TickTackToe(int canvasSizeX, int canvasSizeY, int rows, int cols, int lineToWin, Form1 f)
 {
     form           = f;
     myField        = new Field(canvasSizeX, canvasSizeY, rows, cols);
     this.cols      = cols;
     this.rows      = rows;
     cells          = new Mark[rows, cols];
     this.lineToWin = lineToWin;
     lastMove       = new Point();
 }
Ejemplo n.º 13
0
 public MackMethod(float[,] elements)
 {
     this.n        = elements.GetLength(0);
     this.elements = elements;
     this.marks    = new Mark[n, n];
     this.arrClmA  = new List <int>();
     this.arrClmB  = new List <int>();
     ClearMarks();
     MarkMinElements();
     FormClmArrays();
 }
Ejemplo n.º 14
0
 private static void Vertical(Mark[,] field, ref int res, ref Mark type)
 {
     for (int j = 0; j < 3; j++)
     {
         if ((field[0, j] == field[1, j]) && (field[0, j] == field[2, j]) && (field[0, j] != Mark.Empty))
         {
             type = field[0, j];
             res++;
         }
     }
 }
Ejemplo n.º 15
0
 private static void Horizontal(Mark[,] field, ref int res, ref Mark type)
 {
     for (int i = 0; i < 3; i++)
     {
         if ((field[i, 0] == field[i, 1]) && (field[i, 0] == field[i, 2]) && (field[i, 0] != Mark.Empty))
         {
             type = field[i, 0];
             res++;
         }
     }
 }
Ejemplo n.º 16
0
 public static GameResult GetGameResult(Mark[,] field)
 {
     for (int i = 0; i < Mark.GetLength(0); i++)
     {
         for (int j = 0; j < Mark.GetLength(1); j++)
         {
             Console.Write(Mark[i, j]);
         }
     }
     Console.WriteLine();
 }
Ejemplo n.º 17
0
 public static GameResult GetGameResult(Mark[,] field)
 {
     if (CheckWin(field, Mark.Cross))
     {
         return(GameResult.CrossWin);
     }
     if (CheckWin(field, Mark.Circle))
     {
         return(GameResult.CircleWin);
     }
     return(GameResult.Draw);
 }
Ejemplo n.º 18
0
 // Constructor. Perform any necessary data initialisation here.
 // Uncomment the optional parameters if attempting the stretch goal -- keep the default values to avoid breaking unit tests.
 public OxoBoard(/* int width = 3, int height = 3, int inARow = 3 */)
 {
     board = new Mark[3, 3];
     for (int i = 0; i < board.GetLength(0); i++)
     {
         for (int j = 0; j < board.GetLength(1); j++)
         {
             board[i, j] = Mark.None;
         }
     }
     //throw new NotImplementedException("TODO: implement this function and then remove this exception");
 }
Ejemplo n.º 19
0
 // Constructor. Perform any necessary data initialisation here.
 // Uncomment the optional parameters if attempting the stretch goal -- keep the default values to avoid breaking unit tests.
 public OxoBoard(int width = 3, int height = 3, int inARowToWin = 3)
 {
     inARow = inARowToWin;
     Board  = new Mark[width, height];
     for (int y = 0; y < Board.GetLength(1); y++)
     {
         for (int x = 0; x < Board.GetLength(0); x++)
         {
             Board[x, y] = Mark.None;
         }
     }
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Constructor that instantiate a new gameboard.
        /// In the beginning of the game the board has no player marks on it,
        /// this methods therefore construct the empty board for the start of the game.
        /// </summary>
        public Game()
        {
            gameBoard = new Mark[3, 3];

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    gameBoard[i, j] = Mark.Nobody;
                }
            }
        }
Ejemplo n.º 21
0
 void Awake()
 {
     Grids = new Mark[NumberOfColumns, NumberOfRows];
     for (int r = 0; r < NumberOfRows; r++)
     {
         for (int c = 0; c < NumberOfColumns; c++)
         {
             Grids[c, r] = null;
         }
     }
     mBoardCollider = GetComponent <BoxCollider>();
 }
Ejemplo n.º 22
0
        // Constructor. Perform any necessary data initialisation here.
        // Uncomment the optional parameters if attempting the stretch goal -- keep the default values to avoid breaking unit tests.

        //Initialize the board with a 2D array and then iterate through each one of its coordinates, marking them as empty/none therefore creating an "empty" board.
        public OxoBoard(int width = 3, int height = 3, int inARow = 3)
        {
            board = new Mark[3, 3];

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    board[i, j] = Mark.None;
                }
            }
        }
Ejemplo n.º 23
0
 // Constructor. Perform any necessary data initialisation here.
 // Uncomment the optional parameters if attempting the stretch goal -- keep the default values to avoid breaking unit tests.
 public OxoBoard(int width = 3, int height = 3)
 {
     //initialize 3x3 2D char array
     board = new Mark[3, 3];
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < height; y++)
         {
             board[x, y] = Mark.None;
         }
     }
 }
Ejemplo n.º 24
0
        // Constructor. Perform any necessary data initialisation here.
        // Uncomment the optional parameters if attempting the stretch goal -- keep the default values to avoid breaking unit tests.
        public OxoBoard()
        {
            Game_Board = new Mark[width, height];

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Game_Board[x, y] = Mark.None;
                }
            }
        }
Ejemplo n.º 25
0
 // Constructor. Perform any necessary data initialisation here.
 // Uncomment the optional parameters if attempting the stretch goal -- keep the default values to avoid breaking unit tests.
 public OxoBoard(int width = 3, int height = 3)
 {
     throw new NotImplementedException("TODO: implement this function and then remove this exception");
     //initialize 3x3 2D char array
     board = new Mark[3, 3];
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < height; y++)
         {
             board[x, y] = Mark.None;
         }
     }
 }
Ejemplo n.º 26
0
        // Array of Mark Enums set up to represent the board, Array is 2D due to board being 3x3

        // Creating the board and setting each tile as empty
        public OxoBoard()
        {
            boardArray = new Mark[3, 3];
            // 2 For loops used to go through each row and collum of board
            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    // Then for each tile of the board it is set as empty
                    boardArray[x, y] = Mark.None;
                }
            }
        }
Ejemplo n.º 27
0
        // Constructor. Perform any necessary data initialisation here.
        // Uncomment the optional parameters if attempting the stretch goal -- keep the default values to avoid breaking unit tests.
        public OxoBoard(/* int width = 3, int height = 3, int inARow = 3 */)
        {
            width     = height = 3;
            gameBoard = new Mark[width, height];

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    gameBoard[i, j] = Mark.None;
                }
            }
        }
Ejemplo n.º 28
0
        // Constructor. Perform any necessary data initialisation here.
        // Uncomment the optional parameters if attempting the stretch goal -- keep the default values to avoid breaking unit tests.
        public OxoBoard(/* int width = 3, int height = 3, int inARow = 3 */)
        {
            numberMatrix = new Mark[3, 3];
            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    numberMatrix[x, y] = Mark.None;
                }
            }

            // throw new NotImplementedException("TODO: implement this function and then remove this exception");
        }
Ejemplo n.º 29
0
        // Constructor. Perform any necessary data initialisation here.
        // Uncomment the optional parameters if attempting the stretch goal -- keep the default values to avoid breaking unit tests.
        public OxoBoard(/* int width = 3, int height = 3, int inARow = 3 */)
        {
            //Sets up the boards values and sets them all to none
            Squares = new Mark[3, 3];

            for (int y = 0; y < 3; y++)
            {
                for (int x = 0; x < 3; x++)
                {
                    Squares[x, y] = Mark.None;
                }
            }
        }
Ejemplo n.º 30
0
    private Mark[,] Clone(Mark[,] oldBoard)
    {
        Mark[,] board = new Mark[oldBoard.GetLength(0), oldBoard.GetLength(1)];

        for (int x = 0; x < oldBoard.GetLength(0); x++)
        {
            for (int y = 0; y < oldBoard.GetLength(1); y++)
            {
                board[x, y] = oldBoard[x, y];
            }
        }
        return(board);
    }
Ejemplo n.º 31
0
 /// <summary>
 /// Constructs a new 3x3 grid
 /// </summary>
 public Grid()
 {
     this._gridState = new Mark[3, 3];
 }
Ejemplo n.º 32
0
 private Grid3X3(Mark[,] grid)
     : this()
 {
     _grid = grid;
 }
Ejemplo n.º 33
0
 /// <summary>
 /// Constructs a 3x3 grid copied from another grid's gridstate (used by Clone())
 /// </summary>
 /// <param name="otherGridState"></param>
 private Grid(Mark[,] otherGridState)
 {
     this._gridState = otherGridState;
 }