Beispiel #1
0
        private void CalculateRoute(OrientedCell from, Func <CellCandidate, bool> CheckCand, Func <CellCandidate, bool> NewCand)
        {
            var  candidats = new CandidatesQueue();           //ToDo calculate for giant
            bool end       = false;

            UnitImpl unit = from.cell.unit;

            candidats.Enqueue(new CellCandidate(from, 0, null));
            while (candidats.Count > 0 && !end)
            {
                CellCandidate cand = candidats.Dequeue();
                if (CheckCand(cand))
                {
                    List <OrientedCell> neighbor_cells = gameboard.GetOneMoveCells(cand.cell_ref, unit);
                    foreach (var cell in neighbor_cells)
                    {
                        CellCandidate cell_cand = candidats.FindCandidate(cell);
                        if (cell_cand == null || cell_cand.route_cnt > cand.route_cnt + 1)
                        {
                            var new_cand = new CellCandidate(cell, cand.route_cnt + 1, cand);
                            candidats.Enqueue(new_cand);

                            if (!NewCand(new_cand))
                            {
                                end = true;
                                break;
                            }
                        }
                    }
                }
            }
        }