Пример #1
0
 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
 }
Пример #2
0
 public HashSet<Piece> GetOffboard(Player player)
 {
     if (!offboard.ContainsKey(player))
     {
         offboard.Add(player, new HashSet<Piece>());
     }
     return offboard[player];
 }
Пример #3
0
 internal Piece(string type, Player owner, Game game)
 {
     this.Type = type;
     this.Owner = owner;
     this.Game = game;
 }
Пример #4
0
 public IEnumerable<Coords> EnumerateCoords(GameState state, Player asker)
 {
     var coords = new List<Coords>();
     PossibleCoordsToArray(state, new int[0], 0, asker, coords);
     return coords;
 }
Пример #5
0
 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;
 }
Пример #6
0
 private Coords IdentityTransformation(Player p, Coords c)
 {
     return c;
 }
Пример #7
0
 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);
     }
 }
Пример #8
0
 public Piece PieceAt(GameState state, Coords c, Player asker)
 {
     Piece p;
     if (state.Board.TryGetValue(Transformation(asker, c), out p)) return p;
     return null;
 }
Пример #9
0
        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;
        }
Пример #10
0
 public static void NextPlayer(Context ctx, Player p)
 {
     ctx.GameState.OverrideNextPlayer = p;
 }
Пример #11
0
 public static void Win(Context ctx, Player p)
 {
     p.Won = true;
 }
Пример #12
0
 public static void Lose(Context ctx, Player p)
 {
     p.Lost = true;
 }
Пример #13
0
 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;
 }
Пример #14
0
 internal Coords Transform(Coords c, Player asker)
 {
     return board.Transformation(asker, c);
 }
Пример #15
0
 internal IEnumerable<KeyValuePair<Coords, Piece>> GetPieces(GameState state, Player asker)
 {
     return board.GetPieces(state, null); // FIXME: null should be asker, possible bug?
 }
Пример #16
0
 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]);
     }
 }