public GameForm(StartForm fm1, GameStartConfig gs)
        {
            InitializeComponent();

            MapButton = new Dictionary<int, Button>();

            for (int i = 1; i <= 9; i++)
                MapButton.Add(i, Controls.Find("button_" + i, false).Single() as Button);

            game = new Game(gs, statusLabel, MapButton, this);
            fm = fm1;
            log = gs.Log;
            tlog();
        }
Exemple #2
0
        public override async void Move(Game game)
        {
            foreach (var btn in game.btnMap)
                btn.Value.Enabled = false;

            await Task.Delay(new Random().Next(150, 500));

            switch (currentDifficulty)
            {
                //Movement Heuristics 100%
                case Difficulty.Impossible:
                    game.WriteLog("[AI] Checking for Checkmate possibility.");
                    List<int> CheckMateIndexImpossible = AIAttackAndDefenseLogic(game.pCur.Value, game.btnMap).ToList();
                    if (CheckMateIndexImpossible.Count > 0)
                    {
                        game.WriteLog("[AI] Checkmate movement found! Ignore other heuristics because this is prioritized.");
                        game.form.ProcessInput(game.btnMap[CheckMateIndexImpossible[new Random().Next(0, CheckMateIndexImpossible.Count)]]);
                        return;
                    }

                    game.WriteLog("[AI] Checking for prevent Checkmated possibility.");
                    List<int> DefenseIndexImpossible = AIAttackAndDefenseLogic(game.pCur.Next != null ? game.pCur.Next.Value : game.Players.First.Value, game.btnMap).ToList();
                    if (DefenseIndexImpossible.Count > 0)
                    {
                        game.WriteLog("[AI] Checkmated movement found! Ignore other heuristics because this is prioritized.");
                        game.form.ProcessInput(game.btnMap[DefenseIndexImpossible[new Random().Next(0, DefenseIndexImpossible.Count)]]);
                        return;
                    }

                    game.WriteLog("[AI] Checking best movement!");
                    List<int> MovementHeuristicImpossible = AIMovementLogic(game.pCur.Value, game.pCur.Next != null ? game.pCur.Next.Value : game.Players.First.Value, game.btnMap, 1).ToList();
                    if (MovementHeuristicImpossible.Count > 0)
                    {
                        game.WriteLog("[AI] Best movement found! " + string.Join(", ", MovementHeuristicImpossible));
                        game.form.ProcessInput(game.btnMap[MovementHeuristicImpossible[new Random().Next(0, MovementHeuristicImpossible.Count)]]);
                        return;
                    }

                    game.WriteLog("[AI] No priority heuristics. Continued to next functions.");
                    goto case Difficulty.Easy;

                //Checkmate Heuristics 100%
                case Difficulty.Hard:
                    List<int> CheckMateIndex = AIAttackAndDefenseLogic(game.pCur.Value, game.btnMap).ToList();
                    if (CheckMateIndex.Count > 0)
                    {
                        game.form.ProcessInput(game.btnMap[CheckMateIndex[new Random().Next(0, CheckMateIndex.Count)]]);
                        return;
                    }
                    else goto case Difficulty.Normal;

                //Defense Heuristics && Checkmate Heuristics 20%
                case Difficulty.Normal:
                    if (new Random().Next(0, 10) <= 2 && currentDifficulty == Difficulty.Normal)
                    {
                        List<int> CheckmateIndex = AIAttackAndDefenseLogic(game.pCur.Value, game.btnMap).ToList();
                        if (CheckmateIndex.Count > 0)
                        {
                            game.form.ProcessInput(game.btnMap[CheckmateIndex[new Random().Next(0, CheckmateIndex.Count)]]);
                            return;
                        }
                    }

                    List<int> DefenseIndex = AIAttackAndDefenseLogic(game.pCur.Next != null ? game.pCur.Next.Value : game.Players.First.Value, game.btnMap).ToList();
                    if (DefenseIndex.Count > 0)
                    {
                        game.form.ProcessInput(game.btnMap[DefenseIndex[new Random().Next(0, DefenseIndex.Count)]]);
                        return;
                    }
                    else goto case Difficulty.Easy;

                //Random Move
                case Difficulty.Easy:
                    int RandomMovement = await Task.Run(() =>
                    {
                        int RM;
                        do RM = new Random().Next(1, 10);
                        while (!string.IsNullOrWhiteSpace(game.btnMap[RM].Text));
                        return RM;
                    });
                    game.form.ProcessInput(game.btnMap[RandomMovement]);
                    break;

                default:
                    break;
            }
        }
Exemple #3
0
 public override void Move(Game game)
 {
     foreach (var btn in game.btnMap)
         if (string.IsNullOrWhiteSpace(btn.Value.Text))
             btn.Value.Enabled = true;
 }
Exemple #4
0
 public virtual void Move(Game game) { throw new NotImplementedException(); }