Exemple #1
0
        public static RoboField CreateField(FieldType type, RoboBoard board)
        {
            RoboField field = CreateField(type);

            field.Board = board;
            return(field);
        }
Exemple #2
0
        public RoboBoard CopyBoard()
        {
            RoboBoard board = new RoboBoard();

            board.Load(new StringReader(this.ToStringWriter().ToString()), this.Difficulty);
            board.BoardFile = this.BoardFile;
            return(board);
        }
Exemple #3
0
        public static RoboBoard LoadBoard(String boardPath, bool isRelativePath, Difficulty difficulty)
        {
            String path = (isRelativePath ? Directory.GetCurrentDirectory() + "/" : "") + boardPath;

            Console.WriteLine("Loading Board: " + path);
            RoboBoard board = new RoboBoard();

            board.Load(path, difficulty);
            return(board);
        }
Exemple #4
0
        public static RoboPosition PerformAction(RoboBoard board, ActionPhase actionPhase, RoboAction action, RoboPosition position)
        {
            if (action == null)
            {
                return(position);
            }

            position.Assign(action.PerformAction(position, board));
            position.Assign(PerformAction(board, actionPhase, board.GetField(position).OnRobotAction(actionPhase, action, position), position));
            return(position);
        }
Exemple #5
0
        // MonoRobots.exe --play <relative_ki> <relative_board> <difficulty?>
        private static void PlayGame(String kiPath, String boardPath, Difficulty difficulty)
        {
            RoboManager      roboManager = SetupRoboManager();
            RoboPlayerPlugin roboPlugin  = SetupRoboPlayer(roboManager, kiPath, true);
            RoboBoard        board       = RoboUtils.LoadBoard(boardPath, true, difficulty);

            Console.WriteLine("Start...");

            ExecuteGame(roboManager, board, RoboUtils.CreateCardPile());

            Console.Write(GetResults(roboManager));
            Console.WriteLine("End...");
        }
Exemple #6
0
        public static RoboPosition PlayCardCore(RoboBoard board, RoboCard card, RoboPosition position)
        {
            foreach (RoboAction action in card.GetActionList(position))
            {
                if (position.IsDead || board.GetField(position).IsDestination)
                {
                    return(position);
                }
                position.Assign(PerformAction(board, ActionPhase.ActionCard, action, position));
            }

            position.Assign(PerformAction(board, ActionPhase.ActionConveyor, RoboAction.EMPTY, position));
            position.Assign(PerformAction(board, ActionPhase.ActionPusher, RoboAction.EMPTY, position));
            position.Assign(PerformAction(board, ActionPhase.ActionRotator, RoboAction.EMPTY, position));

            return(position);
        }
Exemple #7
0
        public void StartGame(RoboBoard board, RoboCard[] pile)
        {
            Board = board;

            OnGameStateChange(EventArgs <RoboGameState> .create(RoboGameState.StartGame));

            foreach (RoboPlayerPlugin elem in ActivePlayers)
            {
                elem.PlayCardsCallback = RoboPlayerCallback;
                elem.StartGame(Board.CopyBoard());
                elem.Player.CardPile = new List <RoboCard>(pile);
                elem.Player.StartGame();
                elem.Player.PlayerState = RoboPlayerState.Ready;

                elem.Player.Position.Assign(Board.GetStartPosition());
            }

            OnGameStateChange(EventArgs <RoboGameState> .create(RoboGameState.Ready));
        }
        /// <summary>
        /// Performs a robot movement.
        /// </summary>
        /// <param name="position">Position of the robot before the action.</param>
        /// <param name="board">Board to perform action on.</param>
        /// <returns>Position of robot after performing the action.</returns>
        public override RoboPosition PerformAction(RoboPosition position, RoboBoard board)
        {
            RoboField field = board.GetField(position);

            if (!field.CanLeave(this.Direction))
            {
                return(position);
            }

            RoboPosition result = PerformAction(position);

            RoboField neighbor = board.GetField(result);

            if (neighbor == null || !neighbor.CanEnter(RoboRotation.Rotate(this.Direction, Rotation.Around)))
            {
                return(position);
            }

            return(result);
        }
Exemple #9
0
        private RoboBoard GetBoard(RoboBoard original, RoboPlayer actualPlayer, IEnumerable <RoboPlayer> players)
        {
            RoboBoard board = Board.CopyBoard();

            if (Interaction == RoboPlayerInteraction.Blocked)
            {
                foreach (RoboPlayer player in players)
                {
                    if (player == actualPlayer ||
                        board.GetField(player.Position).IsDestination ||
                        player.Position.IsDead)
                    {
                        continue;
                    }

                    board.Fields[player.Position.X, player.Position.Y] =
                        RoboField.CreateField(FieldType.WallDown | FieldType.WallUp | FieldType.WallLeft | FieldType.WallRight);
                }
            }

            return(board);
        }
Exemple #10
0
        // MonoRobots.exe --stats <relative_ki> <relative_boards> <relative_decks>
        private static void Statistics(String kiPath, String boardsPath, String decksPath, Difficulty difficulty)
        {
            RoboManager roboManager = SetupRoboManager();

            Dictionary <String, Dictionary <String, List <RoboPlayerResult> > > allResults = new Dictionary <String, Dictionary <String, List <RoboPlayerResult> > >();

            int roundsPlayedInTotal = 0;

            foreach (String boardFileName in getFileEnumerable(boardsPath))
            {
                RoboBoard board = RoboUtils.LoadBoard(boardFileName, true, difficulty);
                foreach (String pluginPath in getFileEnumerable(kiPath))
                {
                    RoboPlayerPlugin roboPlugin = SetupRoboPlayer(roboManager, pluginPath, true);

                    Dictionary <String, List <RoboPlayerResult> > boardResults = new Dictionary <String, List <RoboPlayerResult> >();
                    allResults[boardFileName] = boardResults;
                    List <RoboPlayerResult> playerResults = new List <RoboPlayerResult>();
                    boardResults.Add(pluginPath, playerResults);

                    foreach (String deckFileName in getFileEnumerable(decksPath))
                    {
                        RoboCard[] pile = RoboUtils.LoadCardDeck(deckFileName);
                        ExecuteGame(roboManager, board, pile);
                        roundsPlayedInTotal++;

                        RoboPlayerResult singleStat = new RoboPlayerResult(roboPlugin.Player);
                        playerResults.Add(singleStat);
                    }

                    roboManager.DeactivatePlugin(roboPlugin);
                }
            }

            Console.WriteLine("RoundsPlayed: " + roundsPlayedInTotal);
            Console.Write(GetFormattedStatistics(allResults));
        }
Exemple #11
0
 public static RoboPosition PlayCard(RoboBoard board, RoboCard card, RoboPosition position)
 {
     return(PlayCardCore(board, card, new RoboPosition(position)));
 }
Exemple #12
0
 /// <summary>
 /// Performs an action - override to implement action.
 /// </summary>
 /// <param name="position">Position of the robot before the action.</param>
 /// <param name="board">Board to perform action on.</param>
 /// <returns>Position of robot after performing the action.</returns>
 public virtual RoboPosition PerformAction(RoboPosition position, RoboBoard board)
 {
     return(PerformAction(position));
 }
Exemple #13
0
 private static void ExecuteGame(RoboManager roboManager, RoboBoard board, RoboCard[] deck)
 {
     roboManager.StartGame(board, deck);
     roboManager.StartRound();
     autoEvent.WaitOne();
 }