public override void SetEnablePositions(ISituation situation, out Positions enableMovein, out Positions enableCapture) { enableMovein = new Positions(); enableCapture = new Positions(); PieceRook.RookShift(this.GameSide, situation, this.Position, enableMovein, enableCapture); PieceBishop.BishopShift(this.GameSide, situation, this.Position, enableMovein, enableCapture); }
public ErrorOccurenceService(ApplicationContext context, ISituation situationService, ILevel levelService, IError errorService) { _context = context; _situationService = situationService; _levelService = levelService; _errorService = errorService; }
public override void SetEnablePositions(ISituation situation, out Positions enableMovein, out Positions enableCapture) { enableCapture = new Positions(); enableMovein = new Positions(); Position aPos = this.Position.ShiftWestNorth(); Position bPos = this.Position.ShiftEastNorth(); Position cPos = this.Position.ShiftWestSouth(); Position dPos = this.Position.ShiftEastSouth(); if (aPos != Position.Empty) { Position.Shift(this.GameSide, situation, aPos.ShiftNorth(), enableMovein, enableCapture); Position.Shift(this.GameSide, situation, aPos.ShiftWest(), enableMovein, enableCapture); } if (bPos != Position.Empty) { Position.Shift(this.GameSide, situation, bPos.ShiftNorth(), enableMovein, enableCapture); Position.Shift(this.GameSide, situation, bPos.ShiftEast(), enableMovein, enableCapture); } if (cPos != Position.Empty) { Position.Shift(this.GameSide, situation, cPos.ShiftWest(), enableMovein, enableCapture); Position.Shift(this.GameSide, situation, cPos.ShiftSouth(), enableMovein, enableCapture); } if (dPos != Position.Empty) { Position.Shift(this.GameSide, situation, dPos.ShiftEast(), enableMovein, enableCapture); Position.Shift(this.GameSide, situation, dPos.ShiftSouth(), enableMovein, enableCapture); } }
public bool Equals(ISituation <T> other) { if (this == other) { return(true); } return((Rule.Equals(other.Rule)) && (Predicate.Equals(other.Predicate) && (Input.Equals(other.Input)))); }
public ErrorOccurrencesController(IErrorOccurrence service, IUser userService, IError errorService, ISituation situationService, IMapper mapper) { _service = service; _userService = userService; _errorService = errorService; _situationService = situationService; _mapper = mapper; }
public override void SetEnablePositions(ISituation situation, out Positions enableMovein, out Positions enableCapture) { enableMovein = new Positions(); enableCapture = new Positions(); Position.Shift(this.GameSide, situation, this.Position.ShiftEast(), enableMovein, enableCapture); Position.Shift(this.GameSide, situation, this.Position.ShiftSouth(), enableMovein, enableCapture); Position.Shift(this.GameSide, situation, this.Position.ShiftWest(), enableMovein, enableCapture); Position.Shift(this.GameSide, situation, this.Position.ShiftNorth(), enableMovein, enableCapture); Position.Shift(this.GameSide, situation, this.Position.ShiftEastNorth(), enableMovein, enableCapture); Position.Shift(this.GameSide, situation, this.Position.ShiftEastSouth(), enableMovein, enableCapture); Position.Shift(this.GameSide, situation, this.Position.ShiftWestNorth(), enableMovein, enableCapture); Position.Shift(this.GameSide, situation, this.Position.ShiftWestSouth(), enableMovein, enableCapture); }
/// <summary> /// 象的基本路线(即斜向) /// </summary> internal static void BishopShift( Enums.GameSide side, ISituation situation, Position position, Positions moveInPs, Positions capturePs) { bool canContine = true; Position tgtPos = Position.Empty; canContine = true; tgtPos = position; while (canContine) { tgtPos = tgtPos.ShiftEastNorth(); canContine = Position.Shift(side, situation, tgtPos, moveInPs, capturePs); } canContine = true; tgtPos = position; while (canContine) { tgtPos = tgtPos.ShiftEastSouth(); canContine = Position.Shift(side, situation, tgtPos, moveInPs, capturePs); } canContine = true; tgtPos = position; while (canContine) { tgtPos = tgtPos.ShiftWestNorth(); canContine = Position.Shift(side, situation, tgtPos, moveInPs, capturePs); } canContine = true; tgtPos = position; while (canContine) { tgtPos = tgtPos.ShiftWestSouth(); canContine = Position.Shift(side, situation, tgtPos, moveInPs, capturePs); } }
/// <summary> /// 从当前的位置移动到新位置。 /// 而后,判断该位置中是否有棋子,并根据判断结果更新两个Position集合(可移动"位置"集合,可杀棋"位置"集合)。 /// 并返回是否可以继续移动的判断。 /// </summary> /// <param name="situation">当前局面</param> /// <param name="tgtPos">目标位置</param> /// <param name="moveInPs">可移动"位置"集合</param> /// <param name="capturePs">可杀棋"位置"集合</param> /// <param name="enableToMoved">该棋格为空时,是否可以移入,一般是指“兵”,“兵”的斜向的两个棋格对于“兵”来讲能吃子不能移入。</param> /// <returns>移动到新位置后是否可以继续移动(当目标棋格中无棋子)</returns> public static bool Shift( Enums.GameSide side, ISituation situation, Position tgtPos, Positions moveInPs, Positions capturePs, bool enableToMoved) { if (tgtPos == Position.Empty) { return(false); } char pieceChar; if (situation.TryGetPiece(tgtPos.Dot, out pieceChar)) { if (char.IsLower(pieceChar) && side == Enums.GameSide.White) { capturePs.Add(tgtPos); } if (char.IsUpper(pieceChar) && side == Enums.GameSide.Black) { capturePs.Add(tgtPos); } return(false); } else { if (enableToMoved) { moveInPs.Add(tgtPos); return(true); } else { return(false); } } }
public abstract void SetEnablePositions(ISituation situation, out Positions enableMovein, out Positions enableCapture);
public Table Match(string tableName, ref IParametersCollection parameters) { int i = 0; int nonSituationalTables = 0; List <Table> matchedTables = new List <Table>(); var tables = _model.GetTablesByName(tableName); ISituation currentSituation = null; void callback(FormulaExpressionContext sender, QuestionArgs args) { throw new Exception($"{tableName} contains situational expression {currentSituation.Expression} that could not be resolved without answering a question: {args.Parameters[0].Name}. Situational tables should only contain resolveable parameters."); }; foreach (var table in _model.GetTablesByName(tableName)) { i++; if (!table.IsSituational) { nonSituationalTables++; if (nonSituationalTables > 1) { throw new Exception($"found multiple tables found for {tableName} that are non situational. Only one table is allowd to be non situational."); } if (!table.IsSituational && i != tables.Count()) { throw new Exception($"Default table {tableName} should be specified after all situational tables."); } matchedTables.Add(table); continue; } // evaluate situations for inclusivity (meaning one of the expressions should evaluate to true. foreach (var situation in table.Situations) { currentSituation = situation; var formula = new Formula(table.DebugInfo, "__temp__", new List <Function>() { new Function(table.DebugInfo, situation.Expression) }); var context = new FormulaExpressionContext(ref _model, ref parameters, formula, callback, this); var result = context.Evaluate(); if (result.Type != TypeEnum.Boolean) { throw new Exception($"{tableName} contains situational expression {currentSituation.Expression} and should evaluate to a boolean, instead it resolved to a: {result.TypeAsString}."); } if ((bool)result.Value) { matchedTables.Add(table); } } } if (matchedTables.Count == 0) { throw new Exception($"No table matches for {tableName}."); } if (matchedTables.Count > 1 && nonSituationalTables == 0) { throw new Exception($"Ambigous situation evaluation on tables named {tableName}."); } return(matchedTables[0]); }
/// <summary> /// 从当前的位置移动到新位置。 /// 而后,判断该位置中是否有棋子,并根据判断结果更新两个Position集合(可移动"位置"集合,可杀棋"位置"集合)。 /// 并返回是否可以继续移动的判断。 /// </summary> /// <param name="situation">当前局面</param> /// <param name="tgtPos">目标位置</param> /// <param name="moveInPs">可移动"位置"集合</param> /// <param name="capturePs">可杀棋"位置"集合</param> /// <param name="enableToMoved">该棋格为空时,是否可以移入,一般是指“兵”,“兵”的斜向的两个棋格对于“兵”来讲能吃子不能移入。</param> /// <returns>移动到新位置后是否可以继续移动(当目标棋格中无棋子)</returns> public static bool Shift( Enums.GameSide side, ISituation situation, Position tgtPos, Positions moveInPs, Positions capturePs, bool enableToMoved) { if (tgtPos == Position.Empty) return false; char pieceChar; if (situation.TryGetPiece(tgtPos.Dot, out pieceChar)) { if (char.IsLower(pieceChar) && side == Enums.GameSide.White) capturePs.Add(tgtPos); if (char.IsUpper(pieceChar) && side == Enums.GameSide.Black) capturePs.Add(tgtPos); return false; } else { if (enableToMoved) { moveInPs.Add(tgtPos); return true; } else return false; } }
public State[] BuildStates(ISituation RootSituation) { List <State> states; List <SituationCollection> situationCollections; List <SituationCollection> openList; List <ISituation> nextSituations; SituationCollection currentSituationCollection, existingSituationCollection; if (RootSituation == null) { throw new ArgumentNullException("RootSituation"); } states = new List <State>(); situationCollections = new List <SituationCollection>(); openList = new List <SituationCollection>(); currentSituationCollection = new SituationCollection(); currentSituationCollection.State = new State(); currentSituationCollection.Items.Add(RootSituation); situationCollections.Add(currentSituationCollection); states.Add(currentSituationCollection.State); openList.Add(currentSituationCollection); while (openList.Count > 0) { currentSituationCollection = openList[0]; openList.RemoveAt(0); for (char input = char.MinValue; input < char.MaxValue; input++) { nextSituations = new List <ISituation>(); foreach (ISituation situation in currentSituationCollection.Items) { foreach (ITransition transition in situation.Transitions) { if (transition is IReductionTransition reductionTransition) { currentSituationCollection.State.CreateReduction(reductionTransition.Rule); continue; } if (transition is IShiftTransition shiftTransition) { if (shiftTransition.Predicate.Accept(input)) { nextSituations.Add(shiftTransition.TargetSituation); } } } } if (nextSituations.Count == 0) { continue; } existingSituationCollection = situationCollections.FirstOrDefault(item => AreEquals(item.Items, nextSituations)); if (existingSituationCollection == null) { existingSituationCollection = new SituationCollection(); existingSituationCollection.Items = nextSituations; existingSituationCollection.State = new State(); situationCollections.Add(existingSituationCollection); states.Add(existingSituationCollection.State); openList.Add(existingSituationCollection); } currentSituationCollection.State.CreateShift(input, states.IndexOf(existingSituationCollection.State)); } } return(states.ToArray()); }
IState[] IAutomatonTableFactory.BuildStates(ISituation RootSituation) { return(BuildStates(RootSituation)); }
public SituationsController(ISituation service, IMapper mapper) { _service = service; _mapper = mapper; }
public static bool Shift( Enums.GameSide side, ISituation situation, Position tgtPos, Positions moveInPs, Positions capturePs) { return Shift(side, situation, tgtPos, moveInPs, capturePs, true); }
public override void SetEnablePositions(ISituation situation, out Positions enableMovein, out Positions enableCapture) { enableMovein = new Positions(); enableCapture = new Positions(); if (this.GameSide == Enums.GameSide.White) { #region 白兵 if (this.Position.Y < 1) { return; //白兵怎么也不可能在第一行上 } Position tmpPos = Position.Empty; //向北 tmpPos = this.Position.ShiftNorth(); if (tmpPos == Position.Empty) { return; } if (!situation.ContainsPiece(tmpPos.Dot)) { enableMovein.Add(tmpPos); } //再向北(仅当在兵从未动过时) if (this.Position.Y == 1) { tmpPos = tmpPos.ShiftNorth(); if (!situation.ContainsPiece(tmpPos.Dot)) { enableMovein.Add(tmpPos); } } //吃过路兵的判断 if (this.Position.Y == 4) { #region 过路兵 //西北 tmpPos = this.Position.ShiftWest(); if (tmpPos != null) { Piece pawn; Game game = (Game)situation; if (game.TryGetPiece(tmpPos.Dot, out pawn)) { if (pawn is PiecePawn) { if (((PiecePawn)pawn).EnableEnPassanted) { enableMovein.Add(this.Position.ShiftWestNorth()); enableCapture.Add(tmpPos); } } } } //东北 tmpPos = this.Position.ShiftEast(); if (tmpPos != null) { Piece pawn; Game game = (Game)situation; if (game.TryGetPiece(tmpPos.Dot, out pawn)) { if (pawn is PiecePawn) { if (((PiecePawn)pawn).EnableEnPassanted) { enableMovein.Add(this.Position.ShiftEastNorth()); enableCapture.Add(tmpPos); } } } } #endregion } //剑指西北 Position.Shift(this.GameSide, situation, this.Position.ShiftWestNorth(), enableMovein, enableCapture, false); //剑指东北 Position.Shift(this.GameSide, situation, this.Position.ShiftEastNorth(), enableMovein, enableCapture, false); #endregion } else { #region 黑兵 if (this.Position.Y > 6) { return; } Position tmpPos = Position.Empty; //向南 tmpPos = this.Position.ShiftSouth(); if (tmpPos == Position.Empty) { return; } if (!situation.ContainsPiece(tmpPos.Dot)) { enableMovein.Add(tmpPos); } //再向南(仅当在兵从未动过时) if (this.Position.Y == 6) { tmpPos = tmpPos.ShiftSouth(); if (!situation.ContainsPiece(tmpPos.Dot)) { enableMovein.Add(tmpPos); } } //吃过路兵的判断 if (this.Position.Y == 3) { #region 过路兵 //西南 tmpPos = this.Position.ShiftWest(); if (tmpPos != null) { Piece pawn; Game game = (Game)situation; if (game.TryGetPiece(tmpPos.Dot, out pawn)) { if (pawn is PiecePawn) { if (((PiecePawn)pawn).EnableEnPassanted) { enableMovein.Add(this.Position.ShiftWestSouth()); enableCapture.Add(tmpPos); } } } } //东南 tmpPos = this.Position.ShiftEast(); if (tmpPos != null) { Piece pawn; Game game = (Game)situation; if (game.TryGetPiece(tmpPos.Dot, out pawn)) { if (pawn is PiecePawn) { if (((PiecePawn)pawn).EnableEnPassanted) { enableMovein.Add(this.Position.ShiftEastSouth()); enableCapture.Add(tmpPos); } } } } #endregion } //剑指西南 Position.Shift(this.GameSide, situation, this.Position.ShiftWestSouth(), enableMovein, enableCapture, false); //剑指东南 Position.Shift(this.GameSide, situation, this.Position.ShiftEastSouth(), enableMovein, enableCapture, false); #endregion } }
public LogErrorOccurrencesController(ILogErrorOccurrence service, ISituation situationService, IMapper mapper) { _service = service; _situationService = situationService; _mapper = mapper; }
public override void SetEnablePositions(ISituation situation, out Positions enableMovein, out Positions enableCapture) { enableMovein = new Positions(); enableCapture = new Positions(); if (this.GameSide == Enums.GameSide.White) { #region 白兵 if (this.Position.Y < 1) return;//白兵怎么也不可能在第一行上 Position tmpPos = Position.Empty; //向北 tmpPos = this.Position.ShiftNorth(); if (tmpPos == Position.Empty) return; if (!situation.ContainsPiece(tmpPos.Dot)) { enableMovein.Add(tmpPos); } //再向北(仅当在兵从未动过时) if (this.Position.Y == 1) { tmpPos = tmpPos.ShiftNorth(); if (!situation.ContainsPiece(tmpPos.Dot)) { enableMovein.Add(tmpPos); } } //吃过路兵的判断 if (this.Position.Y == 4) { #region 过路兵 //西北 tmpPos = this.Position.ShiftWest(); if (tmpPos != null) { Piece pawn; Game game = (Game)situation; if (game.TryGetPiece(tmpPos.Dot, out pawn)) { if (pawn is PiecePawn) { if (((PiecePawn)pawn).EnableEnPassanted) { enableMovein.Add(this.Position.ShiftWestNorth()); enableCapture.Add(tmpPos); } } } } //东北 tmpPos = this.Position.ShiftEast(); if (tmpPos != null) { Piece pawn; Game game = (Game)situation; if (game.TryGetPiece(tmpPos.Dot, out pawn)) { if (pawn is PiecePawn) { if (((PiecePawn)pawn).EnableEnPassanted) { enableMovein.Add(this.Position.ShiftEastNorth()); enableCapture.Add(tmpPos); } } } } #endregion } //剑指西北 Position.Shift(this.GameSide, situation, this.Position.ShiftWestNorth(), enableMovein, enableCapture, false); //剑指东北 Position.Shift(this.GameSide, situation, this.Position.ShiftEastNorth(), enableMovein, enableCapture, false); #endregion } else { #region 黑兵 if (this.Position.Y > 6) return; Position tmpPos = Position.Empty; //向南 tmpPos = this.Position.ShiftSouth(); if (tmpPos == Position.Empty) return; if (!situation.ContainsPiece(tmpPos.Dot)) { enableMovein.Add(tmpPos); } //再向南(仅当在兵从未动过时) if (this.Position.Y == 6) { tmpPos = tmpPos.ShiftSouth(); if (!situation.ContainsPiece(tmpPos.Dot)) { enableMovein.Add(tmpPos); } } //吃过路兵的判断 if (this.Position.Y == 3) { #region 过路兵 //西南 tmpPos = this.Position.ShiftWest(); if (tmpPos != null) { Piece pawn; Game game = (Game)situation; if (game.TryGetPiece(tmpPos.Dot, out pawn)) { if (pawn is PiecePawn) { if (((PiecePawn)pawn).EnableEnPassanted) { enableMovein.Add(this.Position.ShiftWestSouth()); enableCapture.Add(tmpPos); } } } } //东南 tmpPos = this.Position.ShiftEast(); if (tmpPos != null) { Piece pawn; Game game = (Game)situation; if (game.TryGetPiece(tmpPos.Dot, out pawn)) { if (pawn is PiecePawn) { if (((PiecePawn)pawn).EnableEnPassanted) { enableMovein.Add(this.Position.ShiftEastSouth()); enableCapture.Add(tmpPos); } } } } #endregion } //剑指西南 Position.Shift(this.GameSide, situation, this.Position.ShiftWestSouth(), enableMovein, enableCapture, false); //剑指东南 Position.Shift(this.GameSide, situation, this.Position.ShiftEastSouth(), enableMovein, enableCapture, false); #endregion } }
public LogErrorOccrurence(ApplicationContext context, ISituation situationService) { _context = context; _situationService = situationService; }
public static bool Shift( Enums.GameSide side, ISituation situation, Position tgtPos, Positions moveInPs, Positions capturePs) { return(Shift(side, situation, tgtPos, moveInPs, capturePs, true)); }