예제 #1
0
        public static async Task Main(string[] args)
        {
            try
            {
                Print("2048 bot launched!");
                Print("Ready to beat high scores!");

                IKernel container = BuildContainer();

                IAutomatingControler controler = container.Get <IAutomatingControler>();
                await controler.OpenWebPage();

                IDecisionMaker decisionMaker = container.Get <IDecisionMaker>();
                IGridUpdater   gridUpdater   = container.Get <IGridUpdater>();

                while (true)
                {
                    Stopwatch watch = Stopwatch.StartNew();

                    LineBreak();
                    Print("Starting a new game");

                    Grid grid = new Grid();

                    while (!controler.DetectGameOver())
                    {
                        IEnumerable <GridUpdateInput> updateInputs = controler.ReadGridState();
                        gridUpdater.UpdateGrid(grid, updateInputs);

                        Direction nextDirection = decisionMaker.ChoseDirection(grid);
                        Print($"Moving {nextDirection}");
                        await controler.NextStep(nextDirection);
                    }

                    watch.Stop();

                    long duration = watch.ElapsedMilliseconds;
                    int  score    = controler.ReadScore();

                    Print($"Game finished in {duration}");
                    Print($"Score: {score}");

                    await controler.Replay();
                }
            }
            catch (Exception ex)
            {
                PrintError(ex);
                ExitOnClick();
            }
        }
예제 #2
0
 void Start()
 {
     gridUpdater = GameObject.FindGameObjectWithTag("GridUpdater").GetComponent <IGridUpdater>();
     StartCoroutine(MoveFigureDown());
 }
예제 #3
0
 void Start()
 {
     iGridUpdater = gridUpdater.GetComponent <IGridUpdater>();
     iGridUpdater.onDeleteRowOccured += ScoreCalculate;
 }
예제 #4
0
 void Awake()
 {
     CheckSumSpawnChance();
     iGridUpdater = gridUpdater.GetComponent <IGridUpdater>();
     iGridUpdater.onDownCollisionOccured += SpawnFigure;
 }