public string DrawBoardToString(GenericTicTacToeGame game) { // Since potentially we could be dealing with a huge number of squares (there is no // limit on board size), then use a string builder to save memory StringBuilder str_sp = new StringBuilder(); for (int i = 0; i < game.BoardWidth; i++) { for (int j = 0; j < game.BoardHeight; j++) { Space space = game.SpaceAt(i, j); switch(space.State) { case SpaceState.O: str_sp.Append("O"); break; case SpaceState.X: str_sp.Append("X"); break; default: str_sp.Append("-"); break; } } str_sp.Append(Environment.NewLine); } return str_sp.ToString(); }
private void finishGame(GenericTicTacToeGame game) { foreach (Space s in game.Spaces) { s.State = SpaceState.X; } }
public Space NextMove(GenericTicTacToeGame game) { Random r = new Random(); // Select a random square List<Space> available = game.GetAvailableSpaces(); if(available.Count == 0) // None left return null; else // Get a random space from the remaining set return available.ElementAt(r.Next(0, available.Count-1)); }
private void finishGame(GenericTicTacToeGame game) { foreach(Space s in game.Spaces) { s.State = SpaceState.X; } }
public bool HasStarted(GenericTicTacToeGame game) { return (from s in game.Spaces where s.HasBeenPlayed() select s).FirstOrDefault() != default(Space); }
public void DrawBoardToOutput(GenericTicTacToeGame game) { Console.Write(DrawBoardToString(game)); }