Exemplo n.º 1
0
        //# Takes a string which contains an order and parses it, returning the order in
        //# dictionary format. If the order can't be parsed, return None.
        public static Order parse_order_string(string s)
        {
            string[] tokens = s.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if (tokens.Length != 3) return Order.None;
            Order newOrder = new Order();
            if (!int.TryParse(tokens[0], out newOrder.source)) return Order.None;
            if (!int.TryParse(tokens[1], out newOrder.destination)) return Order.None;
            if (!int.TryParse(tokens[2], out newOrder.num_ships)) return Order.None;

            return newOrder;
        }
Exemplo n.º 2
0
        //# Processes the given order, as if it was given by the given player_id. If
        //# everything goes well, returns true. Otherwise, returns false.
        public static bool issue_order(Order order, int player_id, List<Planet> planets, List<Fleet> fleets, ref int[][] temp_fleets)
        {
            if (temp_fleets == null || temp_fleets.Length == 0) temp_fleets = new int[planets.Count][];
            int src = order.source;
            int dest = order.destination;
            if (src < 0 || src >= planets.Count) return false;
            if (dest < 0 || dest >= planets.Count) return false;
            Planet source_planet = planets[src];
            int owner = source_planet.owner;
            int num_ships = order.num_ships;
            if (owner != player_id) return false;

            if (num_ships > source_planet.num_ships) return false;
            if (num_ships < 0) return false;
            source_planet.num_ships -= num_ships;

            if (temp_fleets[src] == null) temp_fleets[src] = new int[planets.Count];
            temp_fleets[src][dest] += num_ships;

            return true;
        }