Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            BestMoveFinder bmf  = new BestMoveFinder();
            var            move = bmf.FindBestMove("8/1q2k3/8/8/8/1Q6/8/4K3 b - - 0 1");

            Console.WriteLine($"FromX: {move.FromX} FromY: {move.FromY} DestX: {move.DestX} DestY: {move.DestY}");
        }
Ejemplo n.º 2
0
        public void Play()
        {
            gameStateReader.Starting();

            while (true)
            {
                var gameState = gameStateReader.ReadGameState();

                if (Broken(gameState))
                {
                    Thread.Sleep(500);
                    continue;
                }

                if (gameState.ThereIsDanger)
                {
                    Evaluator.MaxHeight = 19;
                }
                else
                {
                    Evaluator.MaxHeight = 4;
                }

                //Console.WriteLine(gameState.Board);
                //Console.WriteLine(string.Join(";", gameState.NextTetriminoes));
                var twp = gameState.FallingTetrimino;
                if (twp == null)
                {
                    continue;
                }

                Tetrimino tetrimino = twp.Tetrimino;
                if (target == null || WrongTetrimino(target.Tetrimino, tetrimino))
                {
                    target = bestMoveFinder.FindBestMove(gameState, twp, stashAllowed);
                    if (target == null)
                    {
                        continue;
                    }
                }

                var moves = new List <Move>();
                if (target.Stash)
                {
                    moves.Add(Move.Stash);
                    target       = null;
                    stashAllowed = false;
                }
                else
                {
                    if (!tetrimino.Equals(target.Tetrimino))
                    {
                        if (CanReachInOneOrTwoCWRotations(tetrimino, target.Tetrimino))
                        {
                            moves.Add(Move.Rotate_CW);
                        }
                        else
                        {
                            moves.Add(Move.Rotate_CWW);
                        }
                    }
                    if (target.Column > twp.LeftCol)
                    {
                        moves.Add(Move.Right);
                    }
                    else if (target.Column < twp.LeftCol)
                    {
                        moves.Add(Move.Left);
                    }
                    if (moves.Count == 0)
                    {
                        moves.Add(Move.Drop);
                        target       = null;
                        stashAllowed = true;
                    }
                }

                //foreach (var move in moves)
                //{
                //    Console.WriteLine($"Making move: {move}");
                //}
                keyPresser.MakeMove(moves);

                //Console.WriteLine(target);
                //Console.WriteLine("------");
            }
        }