//todo change to return whole state private List <Line> GetState() { var state = new BoardStateBase(new List <Line>(), new List <Line>(), type, board); for (int i = 0; i < board.GetLength(0); i++) { for (int j = 0; j < board.GetLength(1); j++) { var cell = CellManager.Get(i, j); if (board[i, j] != type || usedCells.Contains(cell)) { continue; } var factory = new LineModifier(cell, state, GetBackwardsDirections()); factory.AddCellToLines(); foreach (var lineCell in state.MyLines.SelectMany(l => l)) { usedCells.Add(lineCell); } } } state.MyLines.Sort(); state.OppLines.Sort(); return(state.MyLines); }
public string ToString(BoardStateBase boardState) { if (boardState == null) { throw new ArgumentNullException(nameof(boardState)); } int maxValue = boardState.TileCount - 1; int padding = maxValue.ToString().Length + 1; StringBuilder sb = new StringBuilder(); int index = 0; for (int y = 0; y < boardState.Height; y++) { for (int x = 0; x < boardState.Width; x++) { int value = boardState[index++]; string str = value == 0 ? "x" : value.ToString(); sb.Append(str.PadLeft(padding)); } sb.AppendLine(); } return sb.ToString(); }
public static void AddCellToLines(Cell cell, BoardStateBase state) { var factory = new LineModifier(cell, state); factory.AddCellToLines(); state.MyLines.Sort(); state.OppLines.Sort(); }
public LineModifier(Cell cell, BoardStateBase state, IEnumerable <Cell> directions) { addedToSomeLine = false; this.cell = cell; this.state = state; this.directions = directions.ToList(); opponentLineModifier = new OpponentLineModifier(state, skipDirections); singleLineModifier = new SingleLineModifier(state, skipDirections); }
private static IEnumerable <EstimatedCell> GetEstimatedCells(BoardStateBase state, NextCells nextCells) { foreach (var cell in nextCells.MyNextCells) { state.Board[cell.X, cell.Y] = state.MyCellType; var newState = state.GetNewState(cell); var estimate = Estimate(newState.MyLines, newState.OppLines); state.Board[cell.X, cell.Y] = BoardCell.None; yield return(new EstimatedCell(cell, estimate, newState)); } if (nextCells.OppNextCells == null) { yield break; } //foreach (var cell in nextCells.OppNextCells) //{ // board[cell.X, cell.Y] = state.OpponentCellType; // var oppNewLines = GetLinesByAddingCell(cell, state.OppLines, state.OpponentCellType); // var estimate = Estimate(oppNewLines, state.MyLines); // board[cell.X, cell.Y] = BoardCell.None; //} }
protected LineModifierBase(BoardStateBase state, List <Cell> skipDirections) { this.state = state; this.skipDirections = skipDirections; }
public OpponentLineModifier(BoardStateBase state, List <Cell> skipDirections) : base(state, skipDirections) { }
public MirrorLineModifier(BoardStateBase state, List <Cell> skipDirections, CellDirection mirrorCellDir) : base(state, skipDirections) { this.mirrorCellDir = mirrorCellDir; }
public LineModifier(Cell cell, BoardStateBase state) : this(cell, state, GetDirections()) { }
public EstimatedCell(Cell cell, int estimate, BoardStateBase newState) { Cell = cell; Estimate = estimate; BoardState = newState; }
public SingleLineModifier(BoardStateBase state, List <Cell> skipDirections) : base(state, skipDirections) { }