コード例 #1
0
ファイル: frmMain.cs プロジェクト: NoGoAway/Hexbot
        private void BuildHexagons()
        {
            int side = 20;
            Hexagon rhex = new Hexagon(20, 50, side, Hexagon.eFirstPoint.SW);
            hexagons.Add(rhex);
            int rows = 20;
            for (int r = 0; r < rows; r++)
            {
                for (int i = 0; i < 19; i++)
                {
                    Hexagon oHex = hexagons.Last();
                    if (i % 2 == 0)
                    {
                        hexagons.Add(new Hexagon(oHex.E.X, oHex.E.Y, side, Hexagon.eFirstPoint.NW));
                    }
                    else
                    {
                        hexagons.Add(new Hexagon(oHex.E.X, oHex.E.Y, side, Hexagon.eFirstPoint.SW));
                    }
                }
                if (r < rows - 1)
                {
                    hexagons.Add(new Hexagon(rhex.SW.X, rhex.SW.Y, side, Hexagon.eFirstPoint.NW));
                    rhex = hexagons.Last();
                }

            }
            var hseed = 5;
            foreach (var h in hexagons)
            {
                h.SetHeight(GetHeight(hseed));
                hseed = h.Height;
            }
        }
コード例 #2
0
ファイル: frmMain.cs プロジェクト: Circle-of-Hackers/Hexbot
 private void DrawSelectCircle(Hexagon h, PaintEventArgs e, Brush brush)
 {
     int radius = 5;
     float x = h.Center.X - radius;
     float y = h.Center.Y - radius;
     float width = 2 * radius;
     float height = 2 * radius;
     e.Graphics.FillEllipse(brush, x, y, width, height);
 }
コード例 #3
0
ファイル: Robot.cs プロジェクト: NoGoAway/Hexbot
        private int AdjacentMovesAllowed(Hexagon h)
        {
            int result = 0;
            foreach (HexSide hs in h.HexSides)
            {
                var aHex = from h1 in this.HexWorld
                           where h1.HexSides.Contains(hs)
                           && !h1.Equals(h)
                           select h1;

                if (aHex.Count() == 1)
                {
                    Hexagon testHex = aHex.First();
                    MoveResult mr = (HexUtils.isMoveAllowed(h, testHex, this.UpJump, this.DownJump));
                    if (mr.MoveResultStatus == MoveResult.eMoveResult.Success)
                    {
                        result++;
                    }
                }
            }
            return result;
        }
コード例 #4
0
ファイル: HexUtils.cs プロジェクト: Circle-of-Hackers/Hexbot
        public static MoveResult isMoveAllowed(Hexagon fromhex, Hexagon tohex,int jumpup,int jumpdown)
        {
            MoveResult result = new MoveResult(MoveResult.eMoveResult.DNE, "");
            bool isBorder = false;
            string notallowed = "";
            string isalllowed = "";
            if (fromhex == null)
            {
                result.MoveResultStatus = MoveResult.eMoveResult.Success;
                result.ResultMessage = "First move.";
            }
            else
            {
                notallowed = string.Format("Move from height {0} to {1} is NOT allowed!", fromhex.Height.ToString(), tohex.Height.ToString());
                isalllowed = string.Format("Move from height {0} to {1} is allowed.", fromhex.Height.ToString(), tohex.Height.ToString());
                foreach (var hs in fromhex.HexSides)
                {
                    if (tohex.HexSides.Contains(hs))
                    {
                        isBorder = true;
                        break;
                    }
                }
                if (isBorder)
                {
                    if (fromhex.Height == tohex.Height)
                    {
                        result.MoveResultStatus = MoveResult.eMoveResult.Success;
                        result.ResultMessage = isalllowed;
                    }
                    if (fromhex.Height < tohex.Height)
                    {
                        if (fromhex.Height + jumpup >= tohex.Height)
                        {
                            result.MoveResultStatus = MoveResult.eMoveResult.Success;
                            result.ResultMessage = isalllowed;

                        }
                        else
                        {
                            result.MoveResultStatus = MoveResult.eMoveResult.TooLow;
                            result.ResultMessage = notallowed;
                        }
                    }
                    if (fromhex.Height > tohex.Height)
                    {
                        if (fromhex.Height - tohex.Height <= jumpdown)
                        {
                            result.MoveResultStatus = MoveResult.eMoveResult.Success;
                            result.ResultMessage = isalllowed;
                        }
                        else
                        {
                            result.MoveResultStatus = MoveResult.eMoveResult.TooHigh;
                            result.ResultMessage = notallowed;
                        }
                    }
                }
            }

            return result;
        }
コード例 #5
0
ファイル: HexWorld.cs プロジェクト: Circle-of-Hackers/Hexbot
        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;
        }
コード例 #6
0
ファイル: HexWorld.cs プロジェクト: Circle-of-Hackers/Hexbot
        private Hexagon GetAdjacentHexagon(Hexagon hex, HexUtils.eMoveDirection direction)
        {
            Hexagon result = new Hexagon();
            switch (direction)
            {
                case HexUtils.eMoveDirection.N:
                    result = (from h in this.Tiles
                              where h.HexSides.Contains(hex.NSide)
                              && h != hex
                              select h).FirstOrDefault();
                    break;
                case HexUtils.eMoveDirection.NE:
                    result = (from h in this.Tiles
                              where h.HexSides.Contains(hex.NESide)
                              && h != hex
                              select h).FirstOrDefault();
                    break;
                case HexUtils.eMoveDirection.SE:
                    result = (from h in this.Tiles
                              where h.HexSides.Contains(hex.SESide)
                              && h != hex
                              select h).FirstOrDefault();
                    break;
                case HexUtils.eMoveDirection.S:
                    result = (from h in this.Tiles
                              where h.HexSides.Contains(hex.SSide)
                              && h != hex
                              select h).FirstOrDefault();
                    break;
                case HexUtils.eMoveDirection.SW:
                    result = (from h in this.Tiles
                              where h.HexSides.Contains(hex.SWSide)
                              && h != hex
                              select h).FirstOrDefault();
                    break;

                case HexUtils.eMoveDirection.NW:
                    result = (from h in this.Tiles
                              where h.HexSides.Contains(hex.NWSide)
                              && h != hex
                              select h).FirstOrDefault();
                    break;
                default:
                    result = null;
                    break;
            }
            return result;
        }
コード例 #7
0
ファイル: frmMain.cs プロジェクト: NoGoAway/Hexbot
 private void DrawSelectCircle(Hexagon h, PaintEventArgs e,Brush brush)
 {
     //Pen pen = new Pen(Color.FromArgb(255, 0, 0, 0));
     int radius = 5;
     float x = h.Center.X - radius;
     float y = h.Center.Y - radius;
     float width = 2 * radius;
     float height = 2 * radius;
     //e.Graphics.DrawEllipse(pen, x, y, width, height);
     e.Graphics.FillEllipse(brush, x, y, width, height);
 }
コード例 #8
0
ファイル: Robot.cs プロジェクト: Circle-of-Hackers/Hexbot
        private HexUtils.eMoveDirection GetDirectionOfAdjancentHex(Hexagon hex)
        {
            Hexagon chex = this.CurrentHexagon;
            HexUtils.eMoveDirection direction;
            if (hex.SE == chex.NE && hex.SW == chex.NW)
            {
                direction = HexUtils.eMoveDirection.N;
                return direction;
            }
            if (hex.W == chex.NE && hex.SW == chex.E)
            {
                direction = HexUtils.eMoveDirection.NE;
                return direction;
            }
            if (hex.NW == chex.SW && hex.W == chex.E)
            {
                direction = HexUtils.eMoveDirection.SE;
                return direction;

            }
            if (hex.NW == chex.SW && hex.NE == chex.SE)
            {
                direction = HexUtils.eMoveDirection.S;
                return direction;
            }
            if (hex.NE == chex.W && hex.E == chex.SW)
            {
                direction = HexUtils.eMoveDirection.SW;
                return direction;
            }
            if (hex.SE == chex.W && hex.E == chex.NW)
            {
                direction = HexUtils.eMoveDirection.NW;
                return direction;
            }
            return HexUtils.eMoveDirection.DNE;
        }
コード例 #9
0
ファイル: Robot.cs プロジェクト: Circle-of-Hackers/Hexbot
 public void SetCurrentHexagon(Hexagon newhex)
 {
     previousHex = this.CurrentHexagon;
     this.CurrentHexagon = newhex;
 }
コード例 #10
0
ファイル: Robot.cs プロジェクト: Circle-of-Hackers/Hexbot
 public void OnTryMoveComplete(MoveResult mresult, Hexagon newhex)
 {
     if (mresult.MoveResultStatus == MoveResult.eMoveResult.Success)
     {
         this.CurrentHexagon = newhex;
         InitiateLookAround();
     }
     else
     {
         CycleThroughMoves();
     }
 }