Example #1
0
 public bool IsFilledCell(Cell c)
 {
     return c.x >= 0 && c.x < Width && c.y >= 0 && c.y < Height && this[c.y][c.x];
 }
Example #2
0
 public bool IsValidCell(Cell c)
 {
     return c.x >= 0 && c.x < Width && c.y >= 0 && c.y < Height && !this[c.y][c.x];
 }
Example #3
0
 public VisitedInfo(Cell pivot, Cell[] members)
 {
     Pivot = pivot;
     Members = members.ToArray();
     Array.Sort(Members);
 }
Example #4
0
 private bool CellHasJoint(Cell cell, HashSet<Cell> cellsSet)
 {
     return Moves.NeighborFunc.Select(fun => fun(cell)).Any(c => Field.IsFilledCell(c) || cellsSet.Contains(c));
 }
Example #5
0
 public static Cell RelatedCell(Cell pivotOld, Cell pivotNew, Cell cellOld)
 {
     int dy = pivotNew.y - pivotOld.y;
     int dx = pivotNew.x - pivotOld.x;
     int d = -1;
     if (dy % 2 == 0 || (cellOld.y - pivotOld.y) % 2 == 0) d = 0;
     else if (pivotOld.y % 2 == 0) d = 1;
     return new Cell(cellOld.x + dx + d, cellOld.y + dy);
 }
Example #6
0
 public static string PrettyPrintBeforeUpdate(Field field, Unit unit, UnitState state, Dictionary<Cell, char> pathCells = null)
 {
     string res = "";
     var cells = state.GetCells(unit);
     for (int y = 0; y < field.Height; ++y)
     {
         if (y % 2 == 1)
             res += " ";
         for (int x = 0; x < field.Width; ++x)
         {
             Cell c = new Cell(x, y);
             if (pathCells != null && pathCells.ContainsKey(c))
                 res += pathCells[c] + " ";
             else if (field[y][x])
                 res += "* ";
             else if (cells.Contains(c))
                 res += "@ ";
             else
                 res += ". ";
         }
         res += "|\n";
     }
     return res;
 }
Example #7
0
 public static Cell MoveW(Cell c)
 {
     return new Cell(c.x - 1, c.y);
 }
Example #8
0
 public bool Equals(Cell other)
 {
     return x == other.x && y == other.y;
 }
Example #9
0
 public static Cell MoveSE(Cell c)
 {
     return new Cell(c.x + c.y % 2, c.y + 1);
 }
Example #10
0
 public static Cell MoveSW(Cell c)
 {
     return new Cell(c.x - (c.y + 1) % 2, c.y + 1);
 }
Example #11
0
 public static Cell MoveE(Cell c)
 {
     return new Cell(c.x + 1, c.y);
 }
Example #12
0
 private static int HexY(double y, Cell pivot)
 {
     return Convert.ToInt32(pivot.y + y / Math.Sqrt(3) * 2);
 }
Example #13
0
 private static int HexX(double x, Cell pivot)
 {
     if (Math.Abs(x - Math.Round(x)) < 0.01)
         return Convert.ToInt32(Math.Round(pivot.x + x));
     return Convert.ToInt32(Math.Round(pivot.x - 0.5 + pivot.y % 2 + x));
 }
Example #14
0
        public void Update(Cell[] cells)
        {
            int points = 0;
            var usedRows = new HashSet<int>();
            foreach (var c in cells)
            {
                Debug.Assert(!this[c.y][c.x]);
                this[c.y][c.x] = true;
                RowCells(c.y).Add(c.x);
                points++;
                TotalBricks++;
                BricksInField++;
                if (!usedRows.Contains(c.y))
                    usedRows.Add(c.y);
                if (c.y < MinFilledRow) MinFilledRow = c.y;
            }

            var del = new List<int>();
            foreach (var row in usedRows)
                if (RowCells(row).Count == Width)
                    del.Add(row);
            del.Sort();
            for (int i = 0; i < del.Count; i++)
            {
                _cells.RemoveAt(Height - del[i] - 1);
                _cellsInRows.RemoveAt(Height - del[i] - 1);
                _cells.Add(new bool[Width]);
                _cellsInRows.Add(new HashSet<int>());
            }
            MinFilledRow += del.Count;
            BricksInField -= del.Count * Width;

            points += 100 * (del.Count + 1) * del.Count / 2;
            if (_lsOld > 1)
                points += Convert.ToInt32((_lsOld - 1) * points / 10.0);
            Score += points;
            _lsOld = del.Count;

            if (del.Count > 0)
            {
                if (!RowsKilled.ContainsKey(del.Count))
                    RowsKilled.Add(del.Count, 1);
                else RowsKilled[del.Count]++;
            }
        }
Example #15
0
 public static Cell TurnCounter(Cell c, Cell pivot)
 {
     double x = EuclidX(c, pivot);
     double y = EuclidY(c, pivot);
     return new Cell(HexX(x / 2 + Math.Sqrt(3) * y / 2, pivot), HexY(-Math.Sqrt(3) * x / 2 + y / 2, pivot));
 }
Example #16
0
 public InputUnit(Cell[] members, Cell pivot)
 {
     this.members = members;
     this.pivot = pivot;
 }
Example #17
0
 private static double EuclidX(Cell cell, Cell pivot)
 {
     int dy = cell.y - pivot.y;
     int dx = cell.x - pivot.x;
     if (dy % 2 == 0) return dx;
     return dx + 0.5 - pivot.y % 2;
 }
Example #18
0
        private bool TryAddVisitedState(UnitState newState, UnitState state, int funcIndex, out Cell[] cells, out bool isBlockingMove, char moveChar = ANY_CHAR)
        {
            cells = null;
            isBlockingMove = false;
            if (_visited.ContainsKey(newState))
                return false;

            cells = newState.GetCells(_unit);

            if (!cells.All(_field.IsValidCell))
            {
                isBlockingMove = true;
                return false;
            }

            //if (_IsDuplicateState(state, newState))
            //    return false;

            var vi = new VisitInfo
                {
                    MoveFuncIndex = funcIndex,
                    PrevState = state,
                    MoveChar = moveChar,
                    //AllPrevStates = _visited[state].AllPrevStates
                    //   AllPrevStates = new HashSet<UnitState>(_visited[state].AllPrevStates)
                };
              //  vi.AllPrevStates.Add(new UnitState(state.Pivot, _unit.GetCanonicalRotation(state.Rotation)));

            _visited[newState] = vi;
            return true;
        }
Example #19
0
 private static double EuclidY(Cell cell, Cell pivot)
 {
     int dy = cell.y - pivot.y;
     return dy * Math.Sqrt(3) / 2;
 }
Example #20
0
 public UnitState(Cell pivot, int rotation)
 {
     Pivot = pivot;
     Rotation = rotation;
 }
Example #21
0
        private static string _PrettyPrint(Cell[] cells, Cell pivot)
        {
            string res = "";

            Cell minCell = new Cell(pivot.x, pivot.y);
            Cell maxCell = new Cell(pivot.x, pivot.y);

            foreach (var cell in cells)
            {
                minCell.x = Math.Min(minCell.x, cell.x);
                minCell.y = Math.Min(minCell.y, cell.y);
                maxCell.x = Math.Max(maxCell.x, cell.x);
                maxCell.y = Math.Max(maxCell.y, cell.y);
            }

            //var newMembers = cells.Select(cell => new Cell(cell.x - minCell.x, cell.y - minCell.y)).ToList();
            //maxCell.x -= minCell.x;
            //maxCell.y -= minCell.y;
            //Cell newPivot = new Cell(pivot.x - minCell.x, pivot.y - minCell.y);

            //for (int y = 0; y < maxCell.y; ++y)
            //{
            //    for (int x )
            //}

            for (int y = minCell.y; y <= maxCell.y; ++y)
            {
                if (y % 2 == 1)
                    res += " ";
                for (int x = minCell.x; x <= maxCell.x; ++x)
                {
                    Cell c = new Cell(x, y);
                    if (cells.Contains(c))
                    {
                        if (pivot == c)
                            res += "& ";
                        else
                            res += "* ";
                    }
                    else if (pivot == c)
                        res += "# ";
                    else
                        res += ". ";
                }
                res += "\n";
            }

            return res;
        }