コード例 #1
0
ファイル: ai.cs プロジェクト: andreigec/Squarification
        private static bool checkEndGame(game g)
        {
            for (int y = 0; y < g.height; y++)
            {
                for (int x = 0; x < g.width; x++)
                {
                    area a = g.boxes[y][x].lineup;
                    if (a.isAreaUsedInGame && a.isSet == false)
                    {
                        return(false);
                    }

                    a = g.boxes[y][x].linedown;
                    if (a.isAreaUsedInGame && a.isSet == false)
                    {
                        return(false);
                    }

                    a = g.boxes[y][x].lineleft;
                    if (a.isAreaUsedInGame && a.isSet == false)
                    {
                        return(false);
                    }

                    a = g.boxes[y][x].lineright;
                    if (a.isAreaUsedInGame && a.isSet == false)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
コード例 #2
0
ファイル: ai.cs プロジェクト: andreigec/Squarification
        public static void clickOnArea(area a, game g, gamepanel gp)
        {
            if (a.isAreaUsedInGame == false || a.isSet || a.parents[0].thisBox == a)
            {
                return;
            }

            a.isSet = true;
            a.refpanel.BackColor = g.players[0].colour;

            //check boxes
            bool goodmove = false;

            foreach (var v in a.parents)
            {
                if (v.thisBox.isAreaUsedInGame == false || v.thisBox.isSet)
                {
                    continue;
                }

                bool val = checkAndSetFilledBox(v, g);
                if (val)
                {
                    goodmove = true;
                }
            }
            //if the box gets set, that means it was a filled square- the player gets another turn
            if (goodmove == false)
            {
                g.requeuePlayers();
                gp.currentplayercolour.BackColor = g.players[0].colour;
            }
            else
            {
                gamecontroller.updateScoreTable(g, gp);
            }

            //check end game
            if (checkEndGame(g))
            {
                gamecontroller.endGame(g, gp);
            }

            if (g.players[0].isAI)
            {
                Thread.Sleep(100);
                performTurn(g, gp);
            }
        }
コード例 #3
0
ファイル: ai.cs プロジェクト: andreigec/Squarification
        public static void clickOnArea(area a, game g, gamepanel gp)
        {
            if (a.isAreaUsedInGame == false || a.isSet || a.parents[0].thisBox == a)
                return;

            a.isSet = true;
            a.refpanel.BackColor = g.players[0].colour;

            //check boxes
            bool goodmove = false;
            foreach (var v in a.parents)
            {
                if (v.thisBox.isAreaUsedInGame == false || v.thisBox.isSet)
                    continue;

                bool val = checkAndSetFilledBox(v, g);
                if (val)
                    goodmove = true;
            }
            //if the box gets set, that means it was a filled square- the player gets another turn
            if (goodmove == false)
            {
                g.requeuePlayers();
                gp.currentplayercolour.BackColor = g.players[0].colour;
            }
            else
            {
                gamecontroller.updateScoreTable(g, gp);
            }

            //check end game
            if (checkEndGame(g))
            {
                gamecontroller.endGame(g,gp);
            }

            if (g.players[0].isAI)
            {
                Thread.Sleep(100);
                performTurn(g, gp);
            }
        }
コード例 #4
0
        private static void addLine(area a, PanelReplacement p, int count, bool horiz, bool last)
        {
            var P = new PanelReplacement();

            P.Tag = a;

            if (a.isAreaUsedInGame)
            {
                P.BorderWidth  = 1;
                P.BorderColour = defaultcolourline;
                P.BackColor    = Color.White;
            }
            else
            {
                P.BackColor = defaultcolorlinedisabled;
            }

            P.MouseClick += P_MouseClick;

            if (horiz)
            {
                P.Width  = horizw;
                P.Height = horizh;

                a.refpanel = P;
                p.AddControl(P, !last);
            }
            else
            {
                P.Width    = horizh;
                P.Height   = horizw;
                a.refpanel = P;
                p.AddControl(P, !last);
            }
            if (a.isAreaUsedInGame)
            {
                a.parents[0].parent.lines.Add(a);
            }
        }
コード例 #5
0
ファイル: ai.cs プロジェクト: andreigec/Squarification
        private static int checkFilledBoxBlankEdges(area proposedLine)
        {
            int setedgemax = 0;
            int setedge    = 0;

            foreach (box b in proposedLine.parents)
            {
                if (b.thisBox.isAreaUsedInGame == false)
                {
                    continue;
                }

                setedge = 0;
                if (b.lineup.isSet || proposedLine == b.lineup)
                {
                    setedge++;
                }
                if (b.linedown.isSet || proposedLine == b.linedown)
                {
                    setedge++;
                }
                if (b.lineleft.isSet || proposedLine == b.lineleft)
                {
                    setedge++;
                }
                if (b.lineright.isSet || proposedLine == b.lineright)
                {
                    setedge++;
                }

                if (setedgemax == -1 || setedgemax < setedge)
                {
                    setedgemax = setedge;
                }
            }
            return(setedgemax);
        }
コード例 #6
0
        private static void addSquareArea(area a, PanelReplacement p)
        {
            var P = new PanelReplacement();

            P.Tag = a;
            if (a.isAreaUsedInGame)
            {
                P.BorderWidth  = 1;
                P.BorderColour = defaultcolourbox;
                P.BackColor    = Color.White;
            }
            else
            {
                P.BackColor = defaultcolorboxdisabled;
            }

            P.MouseClick += P_MouseClick;

            P.Width    = horizw;
            P.Height   = horizw;
            a.refpanel = P;

            p.AddControl(P, true);
        }
コード例 #7
0
 public static gamepanel getGamePanel(area a)
 {
     return(a.refpanel.Parent.Parent.Parent as gamepanel);
 }
コード例 #8
0
ファイル: ai.cs プロジェクト: andreigec/Squarification
        private static int checkFilledBoxBlankEdges(area proposedLine)
        {
            int setedgemax = 0;
            int setedge = 0;
            foreach (box b in proposedLine.parents)
            {
                if (b.thisBox.isAreaUsedInGame==false)
                    continue;

                setedge = 0;
                if (b.lineup.isSet || proposedLine == b.lineup)
                    setedge++;
                if (b.linedown.isSet || proposedLine == b.linedown)
                    setedge++;
                if (b.lineleft.isSet || proposedLine == b.lineleft)
                    setedge++;
                if (b.lineright.isSet || proposedLine == b.lineright)
                    setedge++;

                if (setedgemax == -1 || setedgemax < setedge)
                    setedgemax = setedge;
            }
            return setedgemax;
        }
コード例 #9
0
        private static void addSquareArea(area a, PanelReplacement p)
        {
            var P = new PanelReplacement();
            P.Tag = a;
            if (a.isAreaUsedInGame)
            {
                P.BorderWidth = 1;
                P.BorderColour = defaultcolourbox;
                P.BackColor = Color.White;
            }
            else
                P.BackColor = defaultcolorboxdisabled;

            P.MouseClick += P_MouseClick;

            P.Width = horizw;
            P.Height = horizw;
            a.refpanel = P;

            p.AddControl(P, true);
        }
コード例 #10
0
        private static void addLine(area a, PanelReplacement p, int count, bool horiz, bool last)
        {
            var P = new PanelReplacement();
            P.Tag = a;

            if (a.isAreaUsedInGame)
            {
                P.BorderWidth = 1;
                P.BorderColour = defaultcolourline;
                P.BackColor = Color.White;
            }
            else
                P.BackColor = defaultcolorlinedisabled;

            P.MouseClick += P_MouseClick;

            if (horiz)
            {
                P.Width = horizw;
                P.Height = horizh;

                a.refpanel = P;
                p.AddControl(P, !last);
            }
            else
            {
                P.Width = horizh;
                P.Height = horizw;
                a.refpanel = P;
                p.AddControl(P, !last);
            }
            if (a.isAreaUsedInGame)
            a.parents[0].parent.lines.Add(a);
        }
コード例 #11
0
 public static gamepanel getGamePanel(area a)
 {
     return a.refpanel.Parent.Parent.Parent as gamepanel;
 }