Exemple #1
0
        public Board(long boardId)
        {
            var newGrid = new Mark[3, 3];

            if (boardId == 0)
            {
                this.GridAllocations = newGrid;
                return;
            }

            for (int position = 0; position < 9; position++)
            {
                var gridPoint = new GridPoint(position);
                newGrid[gridPoint.Y, gridPoint.X] = (Mark)(boardId % 3);
                boardId = boardId / 3;
                if (boardId == 0)
                {
                    break;
                }
            }

            this.GridAllocations = newGrid;
        }
Exemple #2
0
 public static int GetPosition(GridPoint gridPoint)
 {
     return(gridPoint.Y * 3 + gridPoint.X);
 }
Exemple #3
0
        public Mark GetMarkAtLocation(int position)
        {
            var gridPoint = new GridPoint(position);

            return(this.GridAllocations[gridPoint.Y, gridPoint.X]);
        }
Exemple #4
0
        public Board AddMarkToLocation(Mark mark, GridPoint gridPoint)
        {
            var newBoardID = this.GetBoardID() + (long)Math.Pow(3, gridPoint.Position) * (int)mark;

            return(new Board(newBoardID));
        }