Esempio n. 1
0
        public Move[] ComputerMove(Board board)
        {
            Move[]    moves           = new Move[Globals.numMoves];
            ArrayList possible        = board.GetPossibleMoves(this);
            int       currentBestVal  = int.MaxValue;
            Move      currentBestMove = (Move)possible[0];
            int       value;

            foreach (Move n in possible)
            {
                if (n.shoot)
                {
                    continue;
                }
                Coord transform = board.MoveToTransform(n);
                value = ControlPointEvalFunction(Coord.Add(transform, location), board.controlLocations);
                if (value < currentBestVal)
                {
                    currentBestMove = n;
                    currentBestVal  = value;
                }
            }
            //only works for one move!
            moves[0]        = currentBestMove.Clone();
            moves[0].player = this;

            program = moves;
            return(moves);
        }
Esempio n. 2
0
        public void MovePlayer(Move m)
        {
            Coord checkLocation = m.player.location.Clone();
            Coord transform     = new Coord(0, 0);
            int   spaces        = int.Parse(m.target);

            switch (m.dir)
            {
            case "U":
                transform = Coord.U;
                break;

            case "R":
                transform = Coord.R;
                break;

            case "D":
                transform = Coord.D;
                break;

            case "L":
                transform = Coord.L;
                break;
            }

            while (spaces > 0)
            {
                checkLocation = Coord.Add(checkLocation, transform);
                if (IsHoleLocation(checkLocation))
                {
                    m.player.health--;
                    if (m.player.health <= 0)
                    {
                        m.player.health = 3;
                        m.player.score--;
                    }
                    PlayerToSpawn(m.player);
                    if (!supressOutput && !Globals.supressAllOutput)
                    {
                        Console.WriteLine("Player " + (m.player.number + 1) + " fell down a hole!");
                    }
                    break;
                }
                else if (!IsOnBoard(checkLocation) || IsPlayerLocation(checkLocation))
                {
                    break;
                }
                spaces--;
                m.player.location = checkLocation;
            }
        }
Esempio n. 3
0
        public bool[] GetShotsAroundPlayer(Player player)
        {
            bool[] result = new bool[Globals.numShotOptions];
            Coord  start  = player.location;
            Coord  checkLocation;
            int    idx = 0;
            bool   count;

            foreach (Coord t in Coord.shotTransforms)
            {
                checkLocation = start.Clone();
                checkLocation = Coord.Add(checkLocation, t);
                count         = IsOnBoard(checkLocation) ? true : false;
                result[idx]   = count;
                idx++;
            }
            return(result);
        }
Esempio n. 4
0
        public int[] GetSpaceAroundPlayer(Player player)
        {
            int[] result = new int[Globals.numMoveOptions];
            Coord start  = player.location;
            Coord checkLocation;
            int   idx = 0;
            int   count;

            foreach (Coord transform in Coord.moveTransforms)
            {
                count         = 0;
                checkLocation = start.Clone();
                checkLocation = Coord.Add(checkLocation, transform);
                while (IsOnBoard(checkLocation) && !IsHoleLocation(checkLocation) && !IsPlayerLocation(checkLocation))
                {
                    checkLocation = Coord.Add(checkLocation, transform);
                    count++;
                }
                result[idx] = count;
                idx++;
            }
            return(result);
        }
Esempio n. 5
0
        public void PlayerShoot(Move m)
        {
            Coord checkLocation = m.player.location.Clone();
            Coord transform;

            switch (m.dir)
            {
            case "N":
                transform = Coord.N;
                break;

            case "NE":
                transform = Coord.NE;
                break;

            case "E":
                transform = Coord.E;
                break;

            case "SE":
                transform = Coord.SE;
                break;

            case "S":
                transform = Coord.S;
                break;

            case "SW":
                transform = Coord.SW;
                break;

            case "W":
                transform = Coord.W;
                break;

            case "NW":
                transform = Coord.NW;
                break;

            default:
                transform = null;
                break;
            }

            do
            {
                checkLocation = Coord.Add(checkLocation, transform);
                int pl = WhichPlayerLocation(checkLocation);
                if (pl != -1)
                {
                    if (!supressOutput && !Globals.supressAllOutput)
                    {
                        Console.WriteLine("Shot HIT player " + (pl + 1));
                    }
                    switch (m.target)
                    {
                    case "HEAD":
                        players[pl].health--;
                        if (players[pl].health == 0)
                        {
                            players[pl].health = 3;
                            PlayerToSpawn(players[pl]);
                            m.player.score++;
                        }
                        break;

                    case "LARM":
                        foreach (Move p in players[pl].program)
                        {
                            p.ArmHit(true);
                        }
                        break;

                    case "RARM":
                        foreach (Move p in players[pl].program)
                        {
                            p.ArmHit(false);
                        }
                        break;

                    case "LLEG":
                        foreach (Move p in players[pl].program)
                        {
                            p.LegHit(true);
                        }
                        break;

                    case "RLEG":
                        foreach (Move p in players[pl].program)
                        {
                            p.LegHit(false);
                        }
                        break;

                    case "BODY":
                        Coord pushedLoc = Coord.Add(players[pl].location, transform);
                        if (IsOnBoard(pushedLoc) && !IsPlayerLocation(pushedLoc))
                        {
                            if (IsHoleLocation(pushedLoc))
                            {
                                players[pl].health--;
                                if (players[pl].health <= 0)
                                {
                                    players[pl].health = 3;
                                    players[pl].score--;
                                }
                                PlayerToSpawn(players[pl]);
                                m.player.score++;
                                if (!supressOutput && !Globals.supressAllOutput)
                                {
                                    Console.WriteLine("Player " + (m.player.number + 1) + " fell down a hole!");
                                }
                            }
                            else
                            {
                                players[pl].location = pushedLoc;
                            }
                        }
                        break;
                    }
                    break;
                }
            } while (IsOnBoard(checkLocation));
        }