Example #1
0
 public RandomQueue(GameRules rules, PieceType[] types)
 {
     randomPicker.Add(PieceType.MatchAll, rules.MatchAllWeight);
     randomPicker.Add(PieceType.MatchNone, rules.MatchNoneWeight);
     foreach (var type in types)
     {
         randomPicker.Add(type, rules.OtherPiecesWeight / (double)types.Length);
     }
 }
Example #2
0
        public static Game FromJSON(JSONNode json)
        {
            var types = PieceType.FromJSONArray(json["numTypes"].AsArray);
            var board = Board.FromJSON(json["board"]);
            var rules = GameRules.FromJSON(json["rules"]);
            var game  = new Game(board, rules, types);

            foreach (JSONNode js in json["moves"].AsArray)
            {
                game.moves.Push(Move.FromJSON(js));
            }
            return(game);
        }
Example #3
0
        public static IncomingQueue GetQueue(GameRules rules, params PieceType[] types)
        {
            switch (rules.NextTypePolicy)
            {
            case NextTypePolicy.Deterministic:
                return(new DeterministicQueue(types));

            case NextTypePolicy.Random:
                return(new RandomQueue(rules, types));

            case NextTypePolicy.RemovedType:
                return(new NoQueue());
            }
            throw new InvalidGameOperationException("Unknown next type policy: " + rules.NextTypePolicy);
        }
Example #4
0
        public Game(Board board, GameRules rules, PieceType[] types)
        {
            if (types == null || types.Length == 0)
            {
                throw new InvalidGameStateException("Empty or null types");
            }
            if (board == null)
            {
                throw new InvalidGameStateException("Empty or null board");
            }

            this.Rules    = rules;
            this.board    = board;
            this.types    = types;
            this.incoming = IncomingQueue.GetQueue(rules, types);
            this.moves    = new Stack <Move>();
        }
Example #5
0
 public Game(int size, GameRules rules, PieceType[] types) : this(new Board(size), rules, types)
 {
 }