Ejemplo n.º 1
0
        private void transformToInternalForm()
        {
            Cell[,] tmp = cells;
            cells = new Cell[width + height / 2, height];
            for (int i = 0; i < cells.GetLength(0); i++)
                for (int j = 0; j < cells.GetLength(1); j++)
                    cells[i, j] = new Cell();

            for (int i = 0; i < width; i++)
                for (int j = 0; j < height; j++)
                    cells[i + (j + 1) / 2, j] = tmp[i, j];
            width = width + (height + 1) / 2;
        }
Ejemplo n.º 2
0
 bool cellMatches(Cell cell, int color)
 {
     if (cond == Cond.Friend)
         return cell.ant != null && cell.ant.color == color;
     else if (cond == Cond.Foe)
         return cell.ant != null && cell.ant.color != color;
     else if (cond == Cond.FriendWithFood)
         return cell.ant != null && cell.ant.color == color && cell.ant.hasFood;
     else if (cond == Cond.FoeWithFood)
         return cell.ant != null && cell.ant.color != color && cell.ant.hasFood;
     else if (cond == Cond.Food)
         return cell.food > 0;
     else if (cond == Cond.Rock)
         return cell.type == CellType.ROCK;
     else if (cond == Cond.Home)
         return color == 0 && cell.type == CellType.RED_ANTHILL ||
                color == 1 && cell.type == CellType.BLACK_ANTHILL;
     else if (cond == Cond.FoeHome)
         return color == 1 && cell.type == CellType.RED_ANTHILL ||
                color == 0 && cell.type == CellType.BLACK_ANTHILL;
     else if (cond == Cond.FoeMarker)
         return cell.markers[1 - color] > 0;
     else if (cond >= Cond.Marker)
         return (cell.markers[color] & (1 << (cond - Cond.Marker))) != 0;
     else
         Debug.Assert(false);
     return false;
 }
Ejemplo n.º 3
0
 public Map(string fileName)
 {
     FileStream fs = new FileStream(fileName, FileMode.Open);
     StreamReader r = new StreamReader(fs);
     width = Int32.Parse(r.ReadLine());
     height = Int32.Parse(r.ReadLine());
     cells = new Cell[width, height];
     for (int j = 0; j < height; j++)
     {
         string[] elems =
             r.ReadLine().Split(new Char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
         for (int i = 0; i < width; i++)
         {
             cells[i, j] = new Cell();
             if (elems[i] == ".")
                 cells[i, j].type = CellType.EMPTY;
             else if (elems[i] == "#")
                 cells[i, j].type = CellType.ROCK;
             else if (Char.IsDigit(elems[i][0]))
             {
                 cells[i, j].type = CellType.EMPTY;
                 cells[i, j].food = Int32.Parse(elems[i]);
             }
             else if (elems[i] == "+")
                 cells[i, j].type = CellType.RED_ANTHILL;
             else if (elems[i] == "-")
                 cells[i, j].type = CellType.BLACK_ANTHILL;
         }
     }
     r.Close();
     transformToInternalForm();
 }