/// <summary> /// Generates the starting pattern: returns next position for the initial standoff. /// </summary> /// <param name="model">The model.</param> /// <param name="player">The player.</param> /// <param name="enemyDistanceFunc">The enemy distance function.</param> public static IKlopCell GenerateStartingPattern(this IKlopModel model, IKlopPlayer player, Func <IKlopCell, double> enemyDistanceFunc) { if (model == null || player == null || enemyDistanceFunc == null) { throw new ArgumentNullException(); } // TODO: Target sometimes falls behing enemy cells, and, however, target cell is not close to enemy, the path is. // TODO: "Safe path"?? "Safe evaluator".. or SafePathFinder. How to build safe cells map fast? return(model.Cells .Where(c => { if (c.X < 1 || c.Y < 1 || c.X >= model.FieldWidth - 2 || c.Y >= model.FieldHeight - 2) { return false; } if (model.GetNeighborCells(c).Any(cc => cc.Owner != null)) { return false; } var dx1 = Math.Abs(c.X - player.BasePosX); var dy1 = Math.Abs(c.Y - player.BasePosY); return dx1 > 1 && dy1 > 1 && ((dx1 * dx1 + dy1 * dy1) < (Math.Pow(model.FieldHeight, 2) + Math.Pow(model.FieldWidth, 2)) / 3) && (enemyDistanceFunc(c) > model.TurnLength / 1.7); }).Random() ?? model.Cells.Where(c => c.Owner == null).Random()); }
public HintPathHighlighter(IKlopModel model) { _model = model; _model.PropertyChanged += (a, e) => { if (e.PropertyName == "CurrentPlayer") { Unhighlight(); } }; }
/// <summary> /// Sets the model. Must be called to activate CPU player. /// </summary> /// <param name="klopModel">The klop model.</param> public virtual void SetModel(IKlopModel klopModel) { if (klopModel == null) { throw new ArgumentNullException(); } Model = klopModel; Model.PropertyChanged += ModelPropertyChanged; StartWorker(); }
/// <summary> /// Initializes a new instance of the <see cref="KlopPathFinder"/> class. /// </summary> public KlopPathFinder(IKlopModel model, IKlopCellEvaluator cellEvaluator = null) { _klopModel = model; _cellEvaluator = cellEvaluator ?? new KlopCellEvaluator(model); _aStar = new AStar(); _field = new Node[model.FieldWidth, model.FieldHeight]; foreach (IKlopCell cell in _klopModel.Cells) { _field[cell.X, cell.Y] = new Node(cell.X, cell.Y); } }
/// <summary> /// Gets the neighbor cells. /// </summary> /// <param name="cell">The cell.</param> /// <param name="model">The model.</param> /// <returns></returns> private static IEnumerable <IKlopCell> GetNeighborCells(IKlopCell cell, IKlopModel model) { for (int x = -1; x < 1; x++) { for (int y = -1; y < 1; y++) { var xx = cell.X + x; var yy = cell.Y + y; if ((x == y && x == 0) || xx < 0 || yy < 0 || xx >= model.FieldWidth || yy > model.FieldHeight) { continue; } yield return(model[xx, yy]); } } }
public void SetModel(IKlopModel klopModel) { }
/// <summary> /// Determines whether fight is started - there are dead clops on the field. /// </summary> public static bool IsFightStarted(this IKlopModel model) { return(model.Cells.Any(c => c.State == ECellState.Dead /*|| _model.Cells.Count(c => c.Owner != null) > _model.FieldHeight*_model.FieldWidth/8*/)); }
/// <summary> /// Initializes a new instance of the <see cref="KlopCellEvaluator"/> class. /// </summary> /// <param name="model">The model.</param> public KlopCellEvaluator(IKlopModel model) { _klopModel = model; }
/// <summary> /// Sets the model. Must be called to activate CPU player. /// </summary> /// <param name="klopModel">The klop model.</param> /// <exception cref="System.ArgumentNullException"></exception> public override void SetModel(IKlopModel klopModel) { base.SetModel(klopModel); _pathFinder = new KlopPathFinder(klopModel); }