Example #1
0
 public Stone GetStone(int idx)
 {
     Stone ret = new Stone();
     if(list.Count > idx)
     {
         ret = list[idx];
     }
     else
     {
         ret = null;
     }
     return ret;
 }
        public AGI_StoneKindsList(Stone orgSt)
        {
            list = new List<AGI_Stones>();
            ID = idCounter;
            AGI_StoneKindsList.idCounter++;
            AGI_Stones tmp = new AGI_Stones(orgSt);
            list.Add(tmp);
            //tmp.PrintStone();
            for(int i = (int)Kinds.R90; i <= (int)Kinds.REV_R270; i++)
            {
                if (i == (int)Kinds.REV_ORG)
                {
                    tmp = createKinds(list[(int)Kinds.ORIGIN], i, list[(int)Kinds.ORIGIN]);
                }
                else
                {
                    tmp = createKinds(list[i - 1], i, list[(int)Kinds.ORIGIN]);
                }
                list.Add(tmp);
               //     tmp.PrintStone();
            }

            /* 重複する石の削除 */
            /* 回転・反転により石の形が重複した場合、片方の石を破壊(null)する */
            Dictionary<String, int> overlapCheck = new Dictionary<String, int>();
            for(int i = (int)Kinds.ORIGIN; i <= (int)Kinds.REV_R270; i++)
            {
                String str = "";
                for(int j=0; j < list[i].GetSize(); j++)
                {
                    str += list[i].GetNum(j).ToString();
                }

                if(overlapCheck.ContainsKey(str) == true) /* すでに格納済みの形 */
                {
                    list[i] = null;
                }
                else
                {
                    overlapCheck.Add(str, 1);
                }

            }
        }
Example #3
0
 public void AddStoneList(Stone s)
 {
     list.Add(s);
 }
Example #4
0
        public void GetProblem(COMMON_MAP map)
        {
            string line = "";
            //FILE INPUT
            //FILELDS
            System.IO.StreamReader file = new System.IO.StreamReader(map.PROBLEM_FILE);
            for (int lineCnt = 0; lineCnt < 32; lineCnt++)
            {
                line = file.ReadLine();
                for (int i = 0; i < line.Length; i++)
                {
                    String tmp = line.Substring(i, 1);
                    pFields.SetField(lineCnt * 32 + i, int.Parse(tmp));
                }
            }

            //pFields.PrintFields();

            line = file.ReadLine(); //空列読み込み
            stoneNum = int.Parse(file.ReadLine()); //石の数読み込み

            for (int lineCnt = 0; lineCnt < stoneNum; lineCnt++)
            {
                Stone tmpStn = new Stone();
                for (int i = 0; i < 8; i++)
                {
                    line = file.ReadLine();
                    for (int j = 0; j < 8; j++)
                    {
                        String tmpSt = line.Substring(j, 1);
                        tmpStn.SetStone(i * 8 + j, int.Parse(tmpSt));
                    }
                }
                line = file.ReadLine(); //空列読み
                list.AddStoneList(tmpStn);
            }
        }
Example #5
0
        public AGI_Stones(Stone st)
        {
            int max_x = 0;
            int min_x = 10;
            int max_y = 0;
            int min_y = 10;
            int initXPoint = -1;
            int initYPoint = -1;

            const int PGM_STONE_MAX_X = 8;
            const int PGM_STONE_MAX_Y = 8;

            /* 石のサイズ測定 */
            for(int i=0; i< PGM_STONE_MAX_X; i++)
            {
                for(int j=0; j< PGM_STONE_MAX_Y; j++)
                {
                    int x_idx = i * PGM_STONE_MAX_Y + j;
                    int y_idx = j * PGM_STONE_MAX_X + i;

                    int getX = st.GetStoneNum(x_idx);
                    int getY = st.GetStoneNum(y_idx);

                    if(getX == 1)
                    {
                        if (max_x < (x_idx % PGM_STONE_MAX_X))
                        {
                            max_x = (x_idx % PGM_STONE_MAX_X);
                        }

                        if(min_x > (x_idx % PGM_STONE_MAX_X))
                        {
                            initXPoint = j;
                            min_x = (x_idx % PGM_STONE_MAX_X);
                        }
                    }
                    if(getY == 1)
                    {
                        if(max_y < (y_idx / PGM_STONE_MAX_X))
                        {
                            max_y = (y_idx / PGM_STONE_MAX_X);
                        }

                        if(min_y > (y_idx / PGM_STONE_MAX_X))
                        {
                            initYPoint = j;
                            min_y = (y_idx / PGM_STONE_MAX_X);
                        }
                    }
                }
            }

            LeftReduct = min_x; /* 出力判定用 */
            UpReduct = min_y; /* 出力判定用 */
            RightReduct = (PGM_STONE_MAX_X - 1) - max_x;
            DownReduct = (PGM_STONE_MAX_Y - 1) - max_y;

            /* 石のサイズ+接触判定分で動的確保 */
            xSize = (max_x - min_x + 1) + 2;    /* +1 はサイズのため(index5 - index3 = size3, +2は両端の接触判定分 */
            ySize = (max_y - min_y + 1) + 2;    /* ↑ */
            stone = new int[xSize * ySize];

            int initPoint = (initYPoint * PGM_STONE_MAX_X) + initXPoint;

            /* StoneからAGI_Stonesへ */
            int cnt = 0 ;
            for(int i=0; i < stone.Length; i++)
            {
                if ((i < xSize) || (i > (xSize * (ySize - 1))))
                {
                    stone[i] = NOTHING;
                }
                else if (((i % xSize) == 0) || ((i % xSize) == (xSize - 1)))
                {
                    stone[i] = NOTHING;
                }
                else
                {

                    stone[i] = st.GetStoneNum(initPoint + cnt);
                    if(cnt < (max_x - min_x))
                    {
                        cnt++;
                    }
                    else
                    {
                        cnt = 0;
                        initPoint += PGM_STONE_MAX_X;
                    }
                }

            }

            /* 接触判定分を設定 */
            for(int i=0; i < stone.Length; i++)
            {
                if (stone[i] == STONE)
                {
                    /* 上下左右を接触セルとする */
                    /* 上 */
                    if (i - xSize >= 0)
                    {
                        if (stone[i - xSize] == NOTHING)
                        {
                            stone[i - xSize] = COVER;
                        }
                    }
                    /* 下 */
                    if(i + xSize < stone.Length)
                    {
                        if (stone[i + xSize] == NOTHING)
                        {
                            stone[i + xSize] = COVER;
                        }
                    }
                    /* 左 */
                    if(i - 1 >= 0)
                    {
                        if(stone[i-1] == NOTHING)
                        {
                            stone[i - 1] = COVER;
                        }
                    }

                    /* 右 */
                    if (i + 1 < stone.Length)
                    {
                        if (stone[i + 1] == NOTHING)
                        {
                            stone[i + 1] = COVER;
                        }
                    }
                }
            }
        }