public override Move GetClone()
        {
            MyMove clone = new MyMove()
            {
                x = x, y = y
            };

            SetCloneInformation(clone);
            return(clone);
        }
Exemple #2
0
        private List <PossibleMove> DecideMoveOLD(Player p, List <List <PossibleMove> > MoveTree)
        {
            var ScoreForBestScorePath = MoveTree.Max(o => o.Sum(j => j.ScoreValue));
            var BestScorePath         = MoveTree.First(o => o.Sum(j => j.ScoreValue) == ScoreForBestScorePath);

            var GroupByFirstMove = MoveTree.GroupBy(o => o.First()).Select(o => new { First = o.Key, Count = o.Count(), Moves = o.ToList() }).
                                   OrderByDescending(o => o.Count).ThenByDescending(o => o.Moves.Average(j => j.Sum(k => k.ScoreValue)));

            var MovesForBestScorePath = GroupByFirstMove.First(o => o.First.Equals(BestScorePath.First())).Count;
            var MovesForBestMovesPath = GroupByFirstMove.First().Count;

            var ScoreForBestMovesPath = GroupByFirstMove.First().Moves.Max(o => o.Sum(j => j.ScoreValue));
            var BestMovesPath         = GroupByFirstMove.First().Moves.First(o => o.Sum(j => j.ScoreValue) == ScoreForBestMovesPath);

            Log.info($"Best path for score is {ScoreForBestScorePath} with {MovesForBestScorePath} paths {BestScorePath.First()}");
            foreach (var s in BestScorePath)
            {
                Log.debug($"Move is {s}");
            }

            Log.info($"Best path for options is {ScoreForBestMovesPath} with {MovesForBestMovesPath} paths {BestMovesPath.First()}");
            foreach (var s in BestMovesPath)
            {
                Log.debug($"Move is {s}");
            }

            List <PossibleMove> MyMove;

            if (p.Strategy == "moves")
            {
                MyMove = BestMovesPath;
            }
            else if (p.Strategy == "score")
            {
                MyMove = BestScorePath;
            }
            else
            {
                if (ScoreForBestMovesPath == ScoreForBestScorePath)
                {
                    MyMove = BestMovesPath;
                }
                else
                {
                    MyMove = BestScorePath;
                }
            }

            Log.important($"Strategy is {p.Strategy} so going with {MyMove.First()}");
            return(MyMove);
        }
    private void Update()
    {
        if (!thread.IsAlive)
        {
            if (gameState.EndGameState(0) == Jai <MyMove> .EndGameState.None)
            {
                MyMove move = currentAI.Call();

                gameState.DoMove(move);

                p1.SetRoot(move);
                p2.SetRoot(move);

                Debug.Log(move.x + " " + move.y + " " + currentAI.GamesPlayed);

                SwitchAI();
            }
        }
    }
 private void FixedUpdate()
 {
     if (!MyAttack.Attacking)
     {
         if (Input.GetKey(KeyCode.A))
         {
             MyMove.MoveTo(Direction.left);
         }
         else if (Input.GetKey(KeyCode.D))
         {
             MyMove.MoveTo(Direction.right);
         }
         if (Input.GetKey(KeyCode.S))
         {
             MyMove.MoveTo(Direction.down);
         }
         else if (Input.GetKey(KeyCode.W))
         {
             MyMove.MoveTo(Direction.up);
         }
     }
 }
Exemple #5
0
        public void TakeTurn(Player p)
        {
            if (p.OutOfMoves)
            {
                Log.important($"{p} is out, skipping turn!");
                return;
            }

            var AllMoves = AllPossibleMoves(p);

            if (AllMoves.Count == 0)
            {
                Log.important($"{p} is out of moves!");
                p.OutOfMoves = true;
                return;
            }

            if (!p.AI)
            {
                TakeHumanTurn(p);
                return;
            }

            var MoveTree = AllMoves.Select(o => new List <PossibleMove>()
            {
                o
            }).ToList();

            var LookSteps = p.LookAhead;

            if (p.Hand.Count(o => o.Type == CardType.PlaceMeeple) == 3)
            {
                LookSteps += 1;
            }

            var SW = new Stopwatch();

            SW.Start();
            bool MovesExhausted = false;

            for (int LookAhead = 1; LookAhead <= LookSteps; LookAhead++)
            {
                Log.info($"Performing lookahead step {LookAhead}");
                var NewMoveTree = new List <List <PossibleMove> >();
                var LogState    = Log.Enabled;
                Log.Enabled = false;

                foreach (var MoveCombo in MoveTree)
                {
                    if (MoveCombo.Count != LookAhead)
                    {
                        continue;
                    }

                    var Virtualboard  = Board.MakeCopy();
                    var VirtualPlayer = Virtualboard.Players[p.ID];

                    foreach (var m in MoveCombo)
                    {
                        Virtualboard.PlayMove(m, VirtualPlayer);
                    }

                    VirtualPlayer.Hand = VirtualPlayer.Hand.Where(o => o.Type != CardType.Shadow).ToList();

                    var FutureMoves = AllPossibleMoves(VirtualPlayer, Virtualboard);
                    if (FutureMoves.Count == 0)
                    {
                        continue;
                    }

                    foreach (var fm in FutureMoves)
                    {
                        var newcombo = MoveCombo.ToList();
                        newcombo.Add(fm);
                        NewMoveTree.Add(newcombo);
                    }
                }

                Log.Enabled = LogState;

                if (NewMoveTree.Count > 0)
                {
                    MoveTree.AddRange(NewMoveTree);
                }
                else
                {
                    Log.important($"All moves enhausted after {LookAhead} steps");
                    MovesExhausted = true;
                    break;
                }
            }

            var BestOneMoveScore = AllMoves.Max(j => j.ScoreValue);
            var BestMove         = AllMoves.First(o => o.ScoreValue == BestOneMoveScore);

            Log.info($"Best greedy move is {BestMove}, considered {MoveTree.Count} moves");

            List <PossibleMove> MyMove;

            if (p.ID == 1)
            {
                MyMove = DecideMove(p, MoveTree);
            }
            else
            {
                MyMove = DecideMoveOLD(p, MoveTree);
            }

            //foreach (var m in MyMove) {
            //    Vis.RenderMove(m);
            //    Vis.Refresh();
            //}

            if (MyMove.Sum(o => o.ScoreValue) < 0 && MovesExhausted && p.Hand.Count(o => o.Type == CardType.Shadow) == 0)
            {
                Log.important($"Not a good move! I pass");
                p.OutOfMoves = true;
            }
            else
            {
                if (MyMove.First().Destination.Type == CardType.Trap)
                {
                    Log.debug($"Its a trap!");
                }

                Board.PlayMove(MyMove.First(), p);
            }
        }
Exemple #6
0
 // Start is called before the first frame update
 void Start()
 {
     pm   = GetComponent <MyMove>();
     anim = GetComponent <Animator>();
     rb   = GetComponent <Rigidbody>();
 }