예제 #1
0
        private void UpdateValidMove(List <ColorCrazePlayerInfo> allPlayers, ColorCrazeBoard.ColorCrazeBoard board)
        {
            position = GetInfo().CurrentLocation;

            List <Point> loc = allPlayers.ConvertAll(new Converter <ColorCrazePlayerInfo, Point>(PlayerToPoint));

            validMove.Clear();

            Point pts = new Point(position.X - 1, position.Y);

            if (position.X > 0 && !loc.Contains(pts))
            {
                validMove.Add(GetPossibleCase(pts, board, ColorCrazeDirection.Left));
            }

            pts = new Point(position.X, position.Y - 1);
            if (position.Y > 0 && !loc.Contains(pts))
            {
                validMove.Add(GetPossibleCase(pts, board, ColorCrazeDirection.Up));
            }

            pts = new Point(position.X + 1, position.Y);
            if (position.X < boardSize - 1 && !loc.Contains(pts))
            {
                validMove.Add(GetPossibleCase(pts, board, ColorCrazeDirection.Right));
            }

            pts = new Point(position.X, position.Y + 1);
            if (position.Y < boardSize - 1 && !loc.Contains(pts))
            {
                validMove.Add(GetPossibleCase(pts, board, ColorCrazeDirection.Down));
            }
        }
예제 #2
0
        private static PossibleCase GetPossibleCase(Point pts, ColorCrazeBoard.ColorCrazeBoard board, ColorCrazeDirection direction)
        {
            PossibleCase possibleCase = new PossibleCase
            {
                Direction = direction,
                owner     = board[pts.X, pts.Y].Owner
            };

            return(possibleCase);
        }
예제 #3
0
 private void Update(List <ColorCrazePlayerInfo> allPlayers, ColorCrazeBoard.ColorCrazeBoard board)
 {
     UpdateValidMove(allPlayers, board);
     if (board.CountSquaresOfOwner(-1) < boardSize * boardSize * 0.1)
     {
         endgame = true;
     }
     foreach (KeyValuePair <int, PlayerScores> pair in idAndPts)
     {
         pair.Value.round = board.CountSquaresOfOwner(pair.Key);
     }
 }
예제 #4
0
            public List <NextMoveCandidate> GetPossibleMoves(ColorCrazeBoard.ColorCrazeBoard board, List <ColorCrazePlayerInfo> allPlayers, int myX, int myY)
            {
                var nextMoves = new List <NextMoveCandidate>();

                if (myX - 1 >= 0 && NotOccupied(allPlayers, myX - 1, myY))
                {
                    nextMoves.Add(new NextMoveCandidate
                    {
                        Direction = ColorCrazeDirection.Left,
                        OwnerId   = board[myX - 1, myY].Owner
                    });
                }

                if (myX + 1 < board.Width && NotOccupied(allPlayers, myX + 1, myY))
                {
                    nextMoves.Add(new NextMoveCandidate
                    {
                        Direction = ColorCrazeDirection.Right,
                        OwnerId   = board[myX + 1, myY].Owner
                    });
                }

                if (myY - 1 >= 0 && NotOccupied(allPlayers, myX, myY - 1))
                {
                    nextMoves.Add(new NextMoveCandidate
                    {
                        Direction = ColorCrazeDirection.Up,
                        OwnerId   = board[myX, myY - 1].Owner
                    });
                }

                if (myY + 1 < board.Height && NotOccupied(allPlayers, myX, myY + 1))
                {
                    nextMoves.Add(new NextMoveCandidate
                    {
                        Direction = ColorCrazeDirection.Down,
                        OwnerId   = board[myX, myY + 1].Owner
                    });
                }

                if (nextMoves.Count == 0) //We are locked :(
                {
                    nextMoves.Add(new NextMoveCandidate {
                        Direction = ColorCrazeDirection.Up
                    });
                }

                return(nextMoves);
            }
예제 #5
0
        private ColorCrazeDecision getOutOfThereBot(ColorCrazeBoard.ColorCrazeBoard gridBoard, List <ColorCrazeDirection> possDirections)
        {
            int X      = GetInfo().CurrentLocation.X;
            int Y      = GetInfo().CurrentLocation.Y;
            int height = gridBoard.Height;
            int width  = gridBoard.Width;

            if (X < width / 2)
            {
                if (possDirections.Contains(ColorCrazeDirection.Right))
                {
                    return(new ColorCrazeDecision(ColorCrazeDirection.Right));
                }
            }

            if (Y < height / 2)
            {
                if (possDirections.Contains(ColorCrazeDirection.Down))
                {
                    return(new ColorCrazeDecision(ColorCrazeDirection.Down));
                }
            }

            if (X > width / 2)
            {
                if (possDirections.Contains(ColorCrazeDirection.Left))
                {
                    return(new ColorCrazeDecision(ColorCrazeDirection.Left));
                }
            }

            if (Y > height / 2)
            {
                if (possDirections.Contains(ColorCrazeDirection.Up))
                {
                    return(new ColorCrazeDecision(ColorCrazeDirection.Up));
                }
            }

            return(new ColorCrazeDecision(new Point(0, 0)));
        }
예제 #6
0
        private int GetScoreForDirection(List <ColorCrazePlayerInfo> allPlayers, ColorCrazeBoard.ColorCrazeBoard board, int x, int y)
        {
            int score = 0;

            if (x >= 0 && x < board.Width && y >= 0 && y < board.Height)
            {
                ColorCrazeGridSquare square = board[x, y];

                foreach (ColorCrazePlayerInfo player in allPlayers)
                {
                    if (player.CurrentLocation.X == x && player.CurrentLocation.Y == y)
                    {
                        return(-1);
                    }
                }

                if (square.Owner == GetInfo().ID)
                {
                    return(0);
                }

                if (square.Color == Color.White)
                {
                    return(1);
                }

                if (leaderboard.TryGetValue(square.Owner, out int value))
                {
                    score += value;
                }

                return(score);
            }

            return(-1);
        }
예제 #7
0
            public List <EnemyData> AnalyzeBoard(ColorCrazeBoard.ColorCrazeBoard board, int myX, int myY)
            {
                var enemies = new List <EnemyData>();


                for (var i = 0; i < board.Width; i++)
                {
                    if (i == MyId)
                    {
                        continue;
                    }

                    enemies.Add(new EnemyData {
                        EnemyId = i
                    });
                }

                Parallel.ForEach(enemies, enemy =>
                {
                    var points = new List <EnemyPoint>();

                    for (var i = 0; i < board.Width; i++)
                    {
                        for (var j = 0; j < board.Height; j++)
                        {
                            if (board[i, j].Owner != enemy.EnemyId)
                            {
                                continue;
                            }

                            var point = new EnemyPoint
                            {
                                X  = i,
                                Y  = j,
                                dX = Math.Abs(i - myX),
                                dY = Math.Abs(j - myY)
                            };


                            if (i <= myX && j < myY)
                            {
                                point.RelativeQuadrant = 1;
                            }
                            else if (i > myX && j <= myY)
                            {
                                point.RelativeQuadrant = 2;
                            }
                            else if (i >= myX && j > myY)
                            {
                                point.RelativeQuadrant = 3;
                            }
                            else if (i < myX && j >= myY)
                            {
                                point.RelativeQuadrant = 4;
                            }

                            points.Add(point);
                        }
                    }

                    enemy.Points = points;
                });

                return(enemies);
            }
예제 #8
0
        private double ScoreSquare(
            ColorCrazeBoard.ColorCrazeBoard colorBoard,
            List <ColorCrazePlayerInfo> players,
            Dictionary <int, int> colorNums,
            Point square,
            int myID,
            int depth,
            int origDepth,
            List <Point> walkedSquares)
        {
            if (square.X < 0 || square.X >= colorBoard.Width || square.Y < 0 || square.Y >= colorBoard.Height)
            {
                return(0);
            }


            var score = (double)colorNums[colorBoard[square.X, square.Y].Owner];

            if (colorBoard[square.X, square.Y].Owner == myID)
            {
                score = 0;
            }
            else if (colorBoard[square.X, square.Y].Owner == -1)
            {
                score = score / 5;
            }

            if (depth == origDepth)
            {
                foreach (var p in players)
                {
                    if (p.CurrentLocation.X == square.X && p.CurrentLocation.Y == square.Y)
                    {
                        return(0);
                    }
                }
            }

            var wouldWalkedSquares = walkedSquares.ToList();

            wouldWalkedSquares.Add(square);

            var ratioDeeper = 0.4;

            if (origDepth == depth)
            {
                ratioDeeper = ratioDeeper * 0.5;
            }

            if (depth > 0)
            {
                score += (ScoreSquare(colorBoard, players, colorNums, new Point(square.X + 1, square.Y), myID, depth - 1, origDepth, wouldWalkedSquares) * ratioDeeper);
                score += (ScoreSquare(colorBoard, players, colorNums, new Point(square.X - 1, square.Y), myID, depth - 1, origDepth, wouldWalkedSquares) * ratioDeeper);
                score += (ScoreSquare(colorBoard, players, colorNums, new Point(square.X, square.Y + 1), myID, depth - 1, origDepth, wouldWalkedSquares) * ratioDeeper);
                score += (ScoreSquare(colorBoard, players, colorNums, new Point(square.X, square.Y - 1), myID, depth - 1, origDepth, wouldWalkedSquares) * ratioDeeper);
            }

            if (colorBoard[square.X, square.Y].Owner == myID)
            {
                score = score / 8;
            }

            return(score);
        }