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; }
public static int GetPosition(GridPoint gridPoint) { return(gridPoint.Y * 3 + gridPoint.X); }
public Mark GetMarkAtLocation(int position) { var gridPoint = new GridPoint(position); return(this.GridAllocations[gridPoint.Y, gridPoint.X]); }
public Board AddMarkToLocation(Mark mark, GridPoint gridPoint) { var newBoardID = this.GetBoardID() + (long)Math.Pow(3, gridPoint.Position) * (int)mark; return(new Board(newBoardID)); }