Exemplo n.º 1
0
        public void PassingWorks()
        {
            Bot           bot          = new Bot();
            MoveRequest   request      = readMessage <MoveRequest>("{'Board':{'state':[[0,0,0,0,0,0,0,0,0],[0,15,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,-27,0,0,-7,9,0,0],[0,0,0,0,0,0,-6,0,-18],[0,0,0,0,-5,0,0,14,-5]]},'AllowedMoves':['0','1','2']}");
            var           allowedMoves = new MoveType[] { MoveType.Attack, MoveType.Pass, MoveType.Strengthen };
            PrintableMove result       = null;

            Assert.DoesNotThrow(() => result = bot.GetPrintableMoveWithDanger(request.Board, new Move(MoveType.Pass, null, null), allowedMoves));
            Console.WriteLine("poep" + result.ToString());
        }
Exemplo n.º 2
0
        private void CalculateSecondMove(List <PrintableMove> combinedMoves, PrintableMove firstMove)
        {
            var resultBoard    = firstMove.board;
            var validNextMoves = new List <Move>();

            foreach (var location in GetMyLocations(resultBoard))
            {
                validNextMoves.AddRange(GetPossibleToLocations(resultBoard, location).Select <BoardLocation, Move>(l => CreateMove(resultBoard, location, l)).Where(m => m.From != m.To));
            }
            var Moves    = validNextMoves.Select(m => GetPrintableMoveWithDanger(resultBoard, m)).OrderBy(m => m.Danger - m.Value);
            var bestMove = Moves.First();

            firstMove.Danger = bestMove.Danger;
            firstMove.Value  = bestMove.Value;
            combinedMoves.Add(firstMove);
        }
Exemplo n.º 3
0
        private void CalculateSecondMove(List <PrintableMove> combinedMoves, PrintableMove firstMove)
        {
            var resultBoard = firstMove.board;

            GameState.CalculateGameState(resultBoard, myColor);
            var validNextMoves = new List <Move>();

            foreach (var location in GameState.myLocations)
            {
                validNextMoves.AddRange(GameState.myPossibleToLocations[location].Select <BoardLocation, Move>(l => CreateMove(resultBoard, location, l)).Where(m => m.From != m.To));
            }
            if (debug)
            {
                Console.WriteLine("\nSecond Moves for location: " + firstMove.ToString());
            }
            validNextMoves.Add(new Move(MoveType.Pass, null, null));
            var Moves    = validNextMoves.Select(m => GetPrintableMoveWithDanger(resultBoard, m, new MoveType[] { MoveType.Attack, MoveType.Pass, MoveType.Strengthen })).OrderBy(m => m.Danger - m.Value);
            var bestMove = Moves.First();

            firstMove.Danger = bestMove.Danger;
            firstMove.Value  = bestMove.Value + firstMove.ValueOfAttackedStone;
            combinedMoves.Add(firstMove);
        }
Exemplo n.º 4
0
        public PrintableMove GetPrintableMoveWithDanger(Board oldBoard, Move m, MoveType[] allowedMoves, bool nextMove = false)
        {
            if (debug)
            {
                Console.WriteLine(new PrintableMove(m, 0, 0, oldBoard, 0).ToString());
            }
            Board board = GetNewBoard(oldBoard, m);

            double totalValue = 0;

            if (m.Type == MoveType.Attack)
            {
                var attackedStoneType = oldBoard.GetStone(m.To);
                switch (attackedStoneType)
                {
                case Stone.None:
                    break;

                case Stone.pebble:
                    totalValue = pebbleValueEnemy;
                    break;

                case Stone.rock:
                    totalValue = rockValueEnemy;
                    break;

                case Stone.boulder:
                    totalValue = boulderValueEnemy;
                    break;

                default:
                    break;
                }
                totalValue *= oldBoard.GetHeight(m.To);
            }
            double valueOfAttackedStone = totalValue;

            if (allowedMoves.Count() == 1)
            {
                return(new PrintableMove(m, 0, totalValue, board, valueOfAttackedStone));
            }
            GameState.CalculateGameState(board, myColor);

            //84b51
            //if (m.From.X == 8 && m.From.Y == 4 && m.To.X == 5 && m.To.Y == 1)
            //{
            //    Console.WriteLine("dees");
            //}



            double totalDanger = 0;

            if (m.Type == MoveType.Strengthen)
            {
                var    toHeight = oldBoard.GetHeight(m.To);
                var    toType   = oldBoard.GetStone(m.To);
                var    fromType = oldBoard.GetStone(m.From);
                double removedValue;
                switch (toType)
                {
                case Stone.None:
                    removedValue = 0;
                    break;

                case Stone.pebble:
                    removedValue = pebbleValue * toHeight;
                    break;

                case Stone.rock:
                    removedValue = rockValue * toHeight;
                    break;

                case Stone.boulder:
                    removedValue = boulderValue * toHeight;
                    break;

                default:
                    removedValue = 0;
                    break;
                }
                double addedValue;
                switch (fromType)
                {
                case Stone.None:
                    addedValue = 0;
                    break;

                case Stone.pebble:
                    addedValue = pebbleValue * toHeight;
                    break;

                case Stone.rock:
                    addedValue = rockValue * toHeight;
                    break;

                case Stone.boulder:
                    addedValue = boulderValue * toHeight;
                    break;

                default:
                    addedValue = 0;
                    break;
                }
                if (debug)
                {
                    Console.WriteLine("value for strengthen: -" + removedValue + " +" + addedValue);
                }
                //addedValue = GameState.myMaxStoneHeight[fromType] <= GameState.hisMaxStoneheight ? addedValue : 0;
                totalValue += 0.5 - removedValue;
            }

            foreach (BoardLocation location in GameState.myLocations)
            {
                var danger = CalculateDanger(board, location);
                if (debug)
                {
                    Console.WriteLine("danger on: " + PrintableMove.GetString(location.X, location.Y) + " = " + danger.ToString());
                }
                totalDanger += danger;
            }

            int hisAmountOfAttacks = 0;

            if (allowedMoves.Count() > 2)
            {
                foreach (var location in GameState.hisLocations)
                {
                    if (CanAttack(board, location))
                    {
                        hisAmountOfAttacks++;
                    }
                }
                if (hisAmountOfAttacks == 0)
                {
                    totalValue += 1000;
                }
            }

            int attackableStones = GameState.hisLocations.Where(s => GameState.myLocations.Where(l => GameState.myAttackMoves[l].Contains(s)).Any()).Count();

            if (attackableStones < 4)
            {
                var noAttackDanger = (4 - attackableStones);
                totalDanger += noAttackDanger;
                if (debug)
                {
                    Console.WriteLine("danger because of attackableStones: " + noAttackDanger.ToString());
                }
            }


            totalDanger = ApplyLoseConditions(board, totalDanger, allowedMoves);

            totalValue = ApplyWinConditions(board, totalValue);
            if (debug)
            {
                Console.WriteLine("totalDanger: " + totalDanger.ToString());
                Console.WriteLine("totalValue: " + totalValue.ToString() + "\n\n");
            }
            return(new PrintableMove(m, totalDanger, totalValue, board, valueOfAttackedStone));
        }