Esempio n. 1
0
        public frmMain()
        {
            InitializeComponent();

            LogWatcher.Logger log_watcher_logger = new LogWatcher.Logger();
            log_watcher_logger.RegisterInfoCallback(
                (string msg) => AddLog(msg));

            log_watcher                     = new LogWatcher.LogWatcher(log_watcher_logger);
            log_watcher.BlockStart         += Log_reader_ActionStart;
            log_watcher.CreateGameEvent    += Log_reader_CreateGameEvent;
            log_watcher.EndTurnEvent       += Log_reader_EndTurnEvent;
            log_watcher.game_state_changed += (Game game_state) =>
            {
                Board.Game board         = new Board.Game();
                bool       parse_success = board.Parse(game_state);

                if (parse_success == false)
                {
                    txtGameEntity.Text = "Failed to parse game state to board.";
                    return;
                }

                if (last_board != null && last_board.Equals(board))
                {
                    return;
                }
                last_board = board;

                this.UpdateBoard(game_state, board);

                var game_stage = GameStageHelper.GetGameStage(game_state);
                txtGameEntity.Text = "Stage: " + game_stage.ToString() + Environment.NewLine;

                ai_engine_.AbortRunner();
                if (game_stage == GameStage.STAGE_PLAYER_CHOICE)
                {
                    ai_engine_.UpdateBoard(board);

                    if (game_state.GetCurrentPlayerEntityId() == game_state.PlayerEntityId)
                    {
                        int seconds = Convert.ToInt32(Math.Round(nudSeconds.Value, 0));
                        int threads = Convert.ToInt32(Math.Round(nudThreads.Value, 0));
                        ai_engine_.Run(seconds, threads);
                    }
                }
            };

            ai_logger_ = new AI.AILogger(ref txtAIEngine);
            ai_engine_ = new AI.AIEngine(ai_logger_);
            ai_engine_.output_message_cb += (System.String msg) =>
            {
                ai_logger_.Info("[Engine] " + msg);
            };
        }
Esempio n. 2
0
 private void TriggerAIHandleBoardAction(GameState game)
 {
     Board.Game board = new Board.Game();
     bool parse_success = board.Parse(game);
     if (parse_success == false)
     {
         this.AddLog("!!!!!!!!!!!!!!!!!!!! Failed to parse board in action start callback!!!!!!!!!!!!!!!");
         return;
     }
     this.ai_communicator.UpdateBoard(board);
 }
Esempio n. 3
0
        private void TriggerAIHandleBoardAction(Game game)
        {
            Board.Game board         = new Board.Game();
            bool       parse_success = board.Parse(game);

            if (parse_success == false)
            {
                this.AddLog("!!!!!!!!!!!!!!!!!!!! Failed to parse board in action start callback!!!!!!!!!!!!!!!");
                return;
            }
            ai_engine_.AbortRunner();
            ai_engine_.UpdateBoard(board);
        }
Esempio n. 4
0
        private void UpdateBoard(Game game_state, Board.Game game)
        {
            this.txtGameEntity.Text += this.GetGameEntityText(game_state);
            this.txtChoices.Text     = this.GetChoicesText(game_state);

            this.txtPlayerHero.Text      = GetPlayerEntityText(game.player);
            this.txtOpponentHero.Text    = GetPlayerEntityText(game.opponent);
            this.txtPlayerSecrets.Text   = this.GetSecretsText(game.player.secrets);
            this.txtOpponentSecrets.Text = this.GetSecretsText(game.opponent.secrets);
            this.txtPlayerHand.Text      = this.GetHandText(game.player.hand, game_state.Entities);
            this.txtOpponentHand.Text    = this.GetHandText(game.opponent.hand, game_state.Entities);
            this.txtPlayerDeck.Text      = this.GetDeckText(game.player.deck);
            this.txtOpponentDeck.Text    = this.GetDeckText(game.opponent.deck);
            this.txtPlayerMinions.Text   = this.GetPlayMinionsText(game.player.minions);
            this.txtOpponentMinions.Text = this.GetPlayMinionsText(game.opponent.minions);
        }
Esempio n. 5
0
        private void UpdateBoardIfNecessary()
        {
            int current_change_id = this.log_reader.GetChangeId();

            if (current_change_id != last_stable_change_id)
            {
                this.last_stable_change_id = current_change_id;
                this.last_stable_time = DateTime.Now;
                return;
            }

            if ((DateTime.Now - this.last_stable_time) < this.stable_time_to_invoke_AI)
            {
                // not stable enough
                return;
            }

            // now the log is stable enough
            // --> invoke AI if we didn't do it yet
            if (this.last_invoke_log_change_id == current_change_id)
            {
                // we've already invoked the AI for this stable log
                return;
            }

            this.last_invoke_log_change_id = current_change_id;

            Board.Game board = new Board.Game();
            bool parse_success = board.Parse(this.log_reader.GetGameState());

            if (parse_success == false)
            {
                this.txtGameEntity.Text = "parse failed";
                return;
            }
            
            if (board.Equals(this.last_invoke_board))
            {
                //this.AddLog("Log changed, but board are the same as the last-invoked one -> skipping");
                return;
            }

            var game = this.log_reader.GetGameState();

            GameState.Entity game_entity;
            if (!game.TryGetGameEntity(out game_entity))
            {
                this.txtGameEntity.Text = "Parse failed: game entity not exists";
                return;
            }

            var game_stage = this.GetGameStage(game);

            txtGameEntity.Text = "Stage: " + game_stage.ToString() + Environment.NewLine;

            if (game_stage == GameStage.STAGE_PLAYER_CHOICE)
            {
                this.ai_communicator.UpdateBoard(board);

                // TODO: this is a trigger point for automatic playing
                // this.ai_communicator.HandleGameBoard(board);

                //this.last_invoke_board = board;
            }

            this.UpdateBoard(board);
        }