示例#1
0
        public void AddRobot(Robot robot)
        {
            if (this.Robots == null)
            {
                this.Robots = new List<Robot>();
            }
            robot.SetCurrentHexagon(GetStartHexOnBottomRow(robot));

            this.Robots.Add(robot);
            robot.LookAround += new EventHandler(OnRobotLookAround);
            robot.TryMove += new EventHandler(OnRobotTryMove);
        }
示例#2
0
        public MoveResult TryMove(HexUtils.eMoveDirection direction, Robot robot)
        {
            MoveResult result = new MoveResult(MoveResult.eMoveResult.DNE, "");

            Hexagon targethex = GetAdjacentHexagon(robot.CurrentHexagon, direction);

            if (targethex != null)
            {
                result = HexUtils.isMoveAllowed(robot.CurrentHexagon, targethex, robot.UpJump, robot.DownJump);

                if (result.MoveResultStatus == MoveResult.eMoveResult.Success)
                {
                    robot.SetCurrentHexagon(targethex);
                    if (targethex.NE.Y == toprowy)
                    {
                        result.MoveResultStatus = MoveResult.eMoveResult.Complete;
                        result.ResultMessage = string.Format("The robot {0} made it across!", robot.SerialNumber.ToString());
                    }
                }
            }
            return result;
        }
示例#3
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            float toprowy = (from h in hexworld.Tiles
                             select h.NE.Y).Max();
            Robot robot = new Robot(2, 3, 2, toprowy);
            hexworld.AddRobot(robot);

            this.Refresh();
        }
示例#4
0
        private Hexagon GetStartHexOnBottomRow(Robot robot)
        {
            Hexagon result = new Hexagon();

            var MaxY = (from h in this.Tiles
                        select h.SE.Y).Max();
            var bottomRow = (from h in this.Tiles
                             where h.SE.Y == MaxY
                             select h);

            this.Tiles.ForEach(hw => hw.Hilighted = false);

            List<Hexagon> BestHexes = new List<Hexagon>();
            int mostmoves = 0;

            foreach (Hexagon h in bottomRow)
            {
                int moves = AdjacentMovesAllowed(h, robot);
                if (moves > 0)
                {
                    bool updateMostMoves = false;
                    if (moves > mostmoves)
                    {
                        BestHexes.Clear();
                        BestHexes.Add(h);
                        updateMostMoves = true;
                        mostmoves = moves;
                    }
                    if (moves == mostmoves)
                    {
                        BestHexes.Add(h);
                    }
                    if (updateMostMoves) { moves = mostmoves; }
                }

            }
            if (BestHexes.Count() == 1)
            {
                result = BestHexes.First();

                //this.CurrentHex.Selected = true;
            }
            else if (BestHexes.Count() > 1)
            {
                Random rand = new Random();
                int pickone = rand.Next(1, BestHexes.Count());
                result = BestHexes[pickone - 1];
                //this.CurrentHex.Selected = true;
            }
            return result;
        }
示例#5
0
        private int AdjacentMovesAllowed(Hexagon h, Robot robot)
        {
            int result = 0;
            foreach (HexSide hs in h.HexSides)
            {
                var aHex = from h1 in this.Tiles
                           where h1.HexSides.Contains(hs)
                           && !h1.Equals(h)
                           select h1;

                if (aHex.Count() == 1)
                {
                    Hexagon testHex = aHex.First();
                    MoveResult mr = (HexUtils.isMoveAllowed(h, testHex, robot.UpJump, robot.DownJump));
                    if (mr.MoveResultStatus == MoveResult.eMoveResult.Success)
                    {
                        result++;
                    }
                }
            }
            return result;
        }
示例#6
0
 private void frmMain_Load(object sender, EventArgs e)
 {
     BuildHexagons();
     Robot robot = new Robot(2, 3, 2, hexagons);
     this.Refresh();
 }