internal Coords GetPosition(GameState state, Player asker) { foreach (var kvp in Game.GetPieces(state, asker)) { if (this == kvp.Value) { return kvp.Key; } } return null; // Piece is not on the board }
public HashSet<Piece> GetOffboard(Player player) { if (!offboard.ContainsKey(player)) { offboard.Add(player, new HashSet<Piece>()); } return offboard[player]; }
internal Piece(string type, Player owner, Game game) { this.Type = type; this.Owner = owner; this.Game = game; }
public IEnumerable<Coords> EnumerateCoords(GameState state, Player asker) { var coords = new List<Coords>(); PossibleCoordsToArray(state, new int[0], 0, asker, coords); return coords; }
public IEnumerable<KeyValuePair<Coords, Piece>> GetPieces(GameState state, Player asker) { var newDict = state.Board.Select(kvp => new KeyValuePair<Coords, Piece>(Transformation(asker, kvp.Key), kvp.Value)); return newDict; }
private Coords IdentityTransformation(Player p, Coords c) { return c; }
private void PossibleCoordsToArray(GameState state, int[] coords, int dimension, Player asker, List<Coords> outList) { if (dimension == Size.Dimension) { Coords c = new Coords(coords); if (IsValidByRules(state, c)) { outList.Add(Transformation(asker, c)); } return; } for (int i = 1; i <= Size[dimension]; i++) { var newCoords = new List<int>(coords); newCoords.Add(i); PossibleCoordsToArray(state, newCoords.ToArray(), dimension + 1, asker, outList); } }
public Piece PieceAt(GameState state, Coords c, Player asker) { Piece p; if (state.Board.TryGetValue(Transformation(asker, c), out p)) return p; return null; }
public bool TryRemove(GameState state, Coords cIn, Player asker) { Coords c = Transformation(asker, cIn); if (c.IsPlaceHolder) throw new ArgumentOutOfRangeException("Non-placeholder coords needed."); if (!IsValidPlace(state, c)) { throw new ArgumentOutOfRangeException("Coords must be inside the board."); } if (!state.Board.ContainsKey(c)) return false; state.Board.Remove(c); return true; }
public static void NextPlayer(Context ctx, Player p) { ctx.GameState.OverrideNextPlayer = p; }
public static void Win(Context ctx, Player p) { p.Won = true; }
public static void Lose(Context ctx, Player p) { p.Lost = true; }
public static Piece ChoosePiece(Context ctx, Player p, IEnumerable<object> set) { if (set.Count() == 0) { return null; } var pieces = set.OfType<Piece>(); int currentPlayerID = ctx.GameState.CurrentPlayerID; ctx.GameState.CurrentPlayerID = p.ID - 1; Piece pi = ctx.Game.AskForPiece(ctx.GameState, pieces); ctx.GameState.CurrentPlayerID = currentPlayerID; return pi; }
internal Coords Transform(Coords c, Player asker) { return board.Transformation(asker, c); }
internal IEnumerable<KeyValuePair<Coords, Piece>> GetPieces(GameState state, Player asker) { return board.GetPieces(state, null); // FIXME: null should be asker, possible bug? }
internal void SetXYZ(Coords cIn, Player asker) { var c = Game.Transform(cIn, asker); if (c.Dimension >= 1) { SetVariable("x", c[0]); } if (c.Dimension >= 2) { SetVariable("y", c[1]); } if (c.Dimension >= 3) { SetVariable("z", c[2]); } }