public static IEnumerable <GameAction> AllActions(State currentState, ActionSide side) { foreach (var block in AllBlocks(currentState, side)) { if (block.CheckError(currentState) == null) { yield return(block); } } foreach (var drop in AllDrops(currentState, side)) { if (drop.CheckError(currentState) == null) { yield return(drop); } } foreach (var move in AllMergeMoveSplit(currentState, side)) { if (move.CheckError(currentState) == null) { yield return(move); } } }
public void ActionSideTest() { ActionSide side = ActionSide.Buy; Assert.AreEqual("BUY", side.Value); Assert.AreEqual("Buy", side.Name); }
private static IEnumerable <GameAction> AllDrops(State currentState, ActionSide side) { var home = side == ActionSide.Red ? currentState.RedHome : currentState.BlueHome; if (currentState[home].IsEmpty()) { yield return new GameDropAction { Location = home, Side = side } } ; foreach (var direction in Movement.AllMoves) { var zone = direction(home, Movement.Blue.CannotWrap, Movement.Red.CannotWrap, Movement.UnmarkedEdges.CannotWrap); if (zone != Location.Undefined && currentState[zone].IsEmpty()) { yield return new GameDropAction { Location = zone, Side = side } } ; } }
public void ThenThereShouldBe(ActionSide side, string countWord, Location location) { var validation = ValidateLocationSideCountInternal(side, countWord, location); var sb = new StringBuilder(); Assert.IsTrue(sb.ValidateRow(_context.BoardState, validation), sb.ToString().Trim()); }
/// <summary> /// Full Constructor /// </summary> /// <param name="clientId">Filter the results of the ReqExecutions() method based on the clientId.</param> /// <param name="acctCode">Filter the results of the ReqExecutions() method based on an account code.</param> /// <param name="time">Filter the results of the ReqExecutions() method based on execution reports received after the specified time.</param> /// <param name="symbol">Filter the results of the ReqExecutions() method based on the order symbol.</param> /// <param name="securityType">Refer to the Contract struct for the list of valid security types.</param> /// <param name="exchange">Filter the results of the ReqExecutions() method based on the order exchange.</param> /// <param name="side">Filter the results of the ReqExecutions() method based on the order action.</param> public KrsExecutionFilter(int clientId, String acctCode, DateTime time, String symbol, SecurityType securityType, String exchange, ActionSide side) { DateTime = time; SecurityType = securityType; ActionSide = side; Convert(); }
public void WhenIDrop(ActionSide side, Location location) { Assert.NotNull(_context.BoardState, "Board State has not been initialized."); var action = new GameDropAction { Location = location, Side = side }; TryApplyAction(action, location); }
public void ActionSideToOrderSide_SellTest() { ActionSide action = ActionSide.Sell; OrderSide orderSide; bool result = Helpers.ActionSideToOrderSide(action, out orderSide); Assert.IsTrue(result); Assert.AreEqual(OrderSide.Sell, orderSide); }
public void WhenIMerge(ActionSide side, Location from, Location to) { Assert.NotNull(_context.BoardState, "Board State has not been initialized."); var action = new GameMergeAction { Location = from, Side = side, Target = to }; TryApplyAction(action, from, to); }
public void GivenIAddPieces(ActionSide side, string definition) { Assert.NotNull(_context.BoardState, "Board State has not been initialized."); _context.BoardState = StateSerializer.ParseSideV1(_context.BoardState, $"{(side == ActionSide.Red ? "R" : "B")}:{definition}"); if (_context.ImageBehavior == BoardImageBehavior.EveryStep || _context.ImageBehavior == BoardImageBehavior.EveryChange) { Console.WriteLine(_context.BoardState.ImageMarkdown()); } }
public void ThenThereShouldBeKingNoSize(ActionSide side, Location location) { var validation = ValidateLocationSideCountInternal(side, "no", location); validation.Type = ValidationFlag.King; validation.Size = null; var sb = new StringBuilder(); Assert.IsTrue(sb.ValidateRow(_context.BoardState, validation), sb.ToString().Trim()); }
/// <summary> /// Initialize the ComboLeg /// </summary> /// <param name="conId">The unique contract identifier specifying the security. See property <see cref="ComboLeg.ConId"/>.</param> /// <param name="ratio">Select the relative number of contracts for the leg you are constructing. See property <see cref="ComboLeg.Ratio"/>.</param> /// <param name="action">The side (buy or sell) for the leg you are constructing. See property <see cref="ComboLeg.Action"/></param> /// <param name="exchange">The exchange to which the complete combination order will be routed. See property <see cref="ComboLeg.Exchange"/>.</param> /// <param name="openClose">Specifies whether the order is an open or close order. Retail customers must use <see cref="ComboOpenClose.Same"/>. See property <see cref="ComboLeg.OpenClose"/></param> /// <param name="shortSaleSlot">ShortSaleSlot of Third Party requires DesignatedLocation to be specified. Non-empty DesignatedLocation values for all other cases will cause orders to be rejected. See Property <see cref="ComboLeg.ShortSaleSlot"/></param> /// <param name="designatedLocation">Use only when shortSaleSlot value = 2. See Property <see cref="ComboLeg.DesignatedLocation"/></param> public ComboLeg(int conId, int ratio, ActionSide action, String exchange, ComboOpenClose openClose, ShortSaleSlot shortSaleSlot, string designatedLocation) { this.conId = conId; this.ratio = ratio; this.action = action; this.exchange = exchange; this.openClose = openClose; this.shortSaleSlot = shortSaleSlot; this.designatedLocation = designatedLocation; }
/// <summary> /// Full Constructor /// </summary> /// <param name="clientId">Filter the results of the ReqExecutions() method based on the clientId.</param> /// <param name="acctCode">Filter the results of the ReqExecutions() method based on an account code.</param> /// <param name="time">Filter the results of the ReqExecutions() method based on execution reports received after the specified time.</param> /// <param name="symbol">Filter the results of the ReqExecutions() method based on the order symbol.</param> /// <param name="securityType">Refer to the Contract struct for the list of valid security types.</param> /// <param name="exchange">Filter the results of the ReqExecutions() method based on the order exchange.</param> /// <param name="side">Filter the results of the ReqExecutions() method based on the order action.</param> public ExecutionFilter(int clientId, String acctCode, DateTime time, String symbol, SecurityType securityType, String exchange, ActionSide side) { this.clientId = clientId; this.acctCode = acctCode; this.time = time; this.symbol = symbol; this.securityType = securityType; this.exchange = exchange; this.side = side; }
public void WhenISplit(ActionSide side, string countWord, Location from, Location to) { var count = CommonSteps.ParseWordNumber(countWord); Assert.NotNull(_context.BoardState, "Board State has not been initialized."); var action = new GameSplitAction { Location = from, Side = side, Target = to, Size = count }; TryApplyAction(action, from, to); }
/// <summary> /// Initialize the ComboLeg /// </summary> /// <param name="conId">The unique contract identifier specifying the security. See property <see cref="ComboLeg.ConId"/>.</param> /// <param name="ratio">Select the relative number of contracts for the leg you are constructing. See property <see cref="ComboLeg.Ratio"/>.</param> /// <param name="action">The side (buy or sell) for the leg you are constructing. See property <see cref="ComboLeg.Action"/></param> /// <param name="exchange">The exchange to which the complete combination order will be routed. See property <see cref="ComboLeg.Exchange"/>.</param> /// <param name="openClose">Specifies whether the order is an open or close order. Retail customers must use <see cref="ComboOpenClose.Same"/>. See property <see cref="ComboLeg.OpenClose"/></param> /// <param name="shortSaleSlot">ShortSaleSlot of Third Party requires DesignatedLocation to be specified. Non-empty DesignatedLocation values for all other cases will cause orders to be rejected. See Property <see cref="ComboLeg.ShortSaleSlot"/></param> /// <param name="designatedLocation">Use only when shortSaleSlot value = 2. See Property <see cref="ComboLeg.DesignatedLocation"/></param> /// <param name="exemptCode">Short Sale Exempt Code. See Property <see cref="ComboLeg.ExemptCode"/></param> public ComboLeg(int conId, int ratio, ActionSide action, String exchange, ComboOpenClose openClose, ShortSaleSlot shortSaleSlot, string designatedLocation, int exemptCode) { this.conId = conId; this.ratio = ratio; this.action = action; this.exchange = exchange; this.openClose = openClose; this.shortSaleSlot = shortSaleSlot; this.designatedLocation = designatedLocation; this.exemptCode = exemptCode; }
public void ThenThereShouldNotBeAny(ActionSide side, Location location) { var contents = _context.BoardState[location]; if (side == ActionSide.Blue) { Assert.IsFalse(contents.BluePiece(), $"{location} unexpectedly did contain a blue piece."); } else if (side == ActionSide.Red) { Assert.IsFalse(contents.RedPiece(), $"{location} unexpectedly did contain a red piece."); } }
private static IEnumerable <GameAction> AllBlocks(State currentState, ActionSide side) { foreach (var location in State.AllBoardLocations) { if (currentState[location].IsEmpty()) { yield return new GameBlockAction { Location = location, Side = side } } ; } }
public void WhenDoes(ActionSide side, string move) { Location location, target; Assert.IsNotEmpty(move, "Move is required"); switch (move.Length) { case 3: //block or drop Assert.IsTrue(Enum.TryParse(move.Substring(1).ToUpper(), out location), $"{move.Substring(1)} was not a valid Location."); if (move[0] == '@') { WhenIDrop(side, location); } else if (move[0] == 'B') { WhenIBlockade(side, location); } else { Assert.Fail($"{move.Substring(0, 1)} was unexpected for a three-character move input." + " Expected B for block or @ for drop."); } break; case 4: //move Assert.IsTrue(Enum.TryParse(move.Substring(0, 2).ToUpper(), out location), $"{move.Substring(0, 2)} was not a valid Location."); Assert.IsTrue(Enum.TryParse(move.Substring(2, 2).ToUpper(), out target), $"{move.Substring(2, 2)} was not a valid Location."); WhenIMove(side, location, target); break; case 5: //merge Assert.IsTrue(Enum.TryParse(move.Substring(0, 2).ToUpper(), out location), $"{move.Substring(0, 2)} was not a valid Location."); Assert.IsTrue(Enum.TryParse(move.Substring(3, 2).ToUpper(), out target), $"{move.Substring(3, 2)} was not a valid Location."); WhenIMerge(side, location, target); break; default: //split Assert.IsTrue(Enum.TryParse(move.Substring(0, 2).ToUpper(), out location), $"{move.Substring(0, 2)} was not a valid Location."); Assert.IsTrue(Enum.TryParse(move.Substring(move.Length - 2, 2).ToUpper(), out target), $"{move.Substring(move.Length - 2, 2)} was not a valid Location."); WhenISplit(side, move.Substring(3, move.Length - 6), location, target); break; } }
public static ISet <Location> GetBridgeSpaces(State state, ActionSide side) { var unconnectedSpaces = new HashSet <Location>(state .Where(kvp => kvp.Value.GetSide(ActionSide.Red, ActionSide.Blue, ActionSide.Undefined) == side) .Select(kvp => kvp.Key)); var bridgeSpaces = new HashSet <Location>(); foreach (var startingLocation in state.RedWallAdjacentLocations) { var potentialBridgeSpaces = new HashSet <Location>(); if (!unconnectedSpaces.Contains(startingLocation)) { continue; } potentialBridgeSpaces.Add(startingLocation); unconnectedSpaces.Remove(startingLocation); var unexpanded = new Stack <Location>(potentialBridgeSpaces); while (unexpanded.Count > 0) { var nextExpand = unexpanded.Pop(); foreach (var mover in Movement.AllMoves) { var adjacent = mover(nextExpand, Movement.Blue.CannotWrap, Movement.Red.CannotWrap, Movement.UnmarkedEdges.CannotWrap); if (unconnectedSpaces.Contains(adjacent)) { potentialBridgeSpaces.Add(adjacent); unexpanded.Push(adjacent); unconnectedSpaces.Remove(adjacent); } } } foreach (var endingLocation in state.BlueWallAdjacentLocations) { if (potentialBridgeSpaces.Contains(endingLocation)) { foreach (var potentialBridgeSpace in potentialBridgeSpaces) { bridgeSpaces.Add(potentialBridgeSpace); } break; } } } return(bridgeSpaces); }
public static Order CreateOrder(ActionSide action, OrderType orderType , double limitPrice, double auxPrice, int quantity, bool outRth, int parentId) { var order = new Order { Action = EnumDescConverter.GetEnumDescription(action), OutsideRth = false, LmtPrice = limitPrice, OrderType = EnumDescConverter.GetEnumDescription(orderType), TotalQuantity = quantity, ParentId = parentId, }; return order; }
public void GameOver(ActionSide side) { Assert.True(_context.BoardState.Flags.GameWon(), $"The game is still in progress: {_context.BoardState.Flags}"); if (side == ActionSide.Red) { Assert.AreEqual(StateFlags.RedWin, _context.BoardState.Flags & StateFlags.RedWin); } else if (side == ActionSide.Blue) { Assert.AreEqual(StateFlags.BlueWin, _context.BoardState.Flags & StateFlags.BlueWin); } }
public static Order CreateOrder(ActionSide action, OrderType orderType , double limitPrice, double auxPrice, int quantity, bool outRth, int parentId) { var order = new Order { Action = EnumDescConverter.GetEnumDescription(action), OutsideRth = false, LmtPrice = limitPrice, OrderType = EnumDescConverter.GetEnumDescription(orderType), TotalQuantity = quantity, ParentId = parentId, }; return(order); }
public void ThenTheBoardHasPiecesMatching(ActionSide side, string definition) { Assert.NotNull(_context.BoardState, "Board State has not been initialized."); var sideRed = side == ActionSide.Red; var testBoard = StateSerializer.ParseSideV1(StateManager.Create(), $"{(sideRed ? "R" : "B")}:{definition}"); var sb = new StringBuilder(); var successful = 0; foreach (var location in State.AllBoardLocations) { if (sideRed) { if (!_context.BoardState[location].RedPiece() && !testBoard[location].RedPiece()) { continue; } } else { if (!_context.BoardState[location].BluePiece() && !testBoard[location].BluePiece()) { continue; } } if ((_context.BoardState[location] & ~(Cell.Locked | Cell.CursePending)) != (testBoard[location] &= ~(Cell.Locked | Cell.CursePending))) { sb.AppendLine( $"At {location}: Expected {testBoard[location] & ~(Cell.Locked | Cell.CursePending)}, " + $"Got {_context.BoardState[location] & ~(Cell.Locked | Cell.CursePending)}"); } else { successful++; } } Console.WriteLine($"Successfully validated {successful} {side} piece{(successful == 1 ? "" : "s")}."); if (sb.Length > 0) { Assert.Fail($"The following board locations had different contents than expected:\r\n{sb}"); } }
private static ValidationType ValidateLocationSideCountInternal(ActionSide side, string countWord, Location location) { var count = CommonSteps.ParseWordNumber(countWord); var validation = new ValidationType { Location = location, Size = count, Type = ValidationFlag.Normal }; if (side == ActionSide.Blue) { validation.Contents = ValidationPiece.Blue; } else if (side == ActionSide.Red) { validation.Contents = ValidationPiece.Red; } return(validation); }
public static bool OrderSideToActionSide(OrderSide orderside, out ActionSide action) { action = ActionSide.Undefined; switch (orderside) { case OrderSide.Buy: action = ActionSide.Buy; break; case OrderSide.Sell: action = ActionSide.Sell; break; default: return(false); } return(true); }
// These converters convert OQ enums to IB enums and back // all follow the same pattern // if a conversion is not possible they return false. // the caller is expected to create an error message and ignore // the class containing the enum which is not convertible public static bool ActionSideToOrderSide(ActionSide action, out OrderSide side) { side = OrderSide.Buy; switch (action) { case ActionSide.Buy: side = OrderSide.Buy; break; case ActionSide.Sell: side = OrderSide.Sell; break; case ActionSide.SShort: side = OrderSide.Sell; break; case ActionSide.Undefined: default: return false; } return true; }
// These converters convert OQ enums to IB enums and back // all follow the same pattern // if a conversion is not possible they return false. // the caller is expected to create an error message and ignore // the class containing the enum which is not convertible public static bool ActionSideToOrderSide(ActionSide action, out OrderSide side) { side = OrderSide.Buy; switch (action) { case ActionSide.Buy: side = OrderSide.Buy; break; case ActionSide.Sell: side = OrderSide.Sell; break; case ActionSide.SShort: side = OrderSide.Sell; break; case ActionSide.Undefined: default: return(false); } return(true); }
private static void GetActionsInternal(Dictionary <Guid, ProposedState> availableActions, HashSet <Guid> history, Func <State, ActionSide, IEnumerable <GameAction> > iteratorFunc, State currentState, ActionSide side) { foreach (var action in iteratorFunc(currentState, side)) { if (action.CheckError(currentState) != null) { continue; } var newState = GameAction.PrepareNextTurn(action.Apply(currentState)); if (history.Add(newState.BoardId)) { availableActions[newState.BoardId] = new ProposedState { Key = newState.BoardId, Action = action, Heuristic = Heuristic.GetScore(newState), Result = newState }; } } }
/// <summary> /// Initialize the ComboLeg /// </summary> /// <param name="conId">The unique contract identifier specifying the security. See property <see cref="ComboLeg.ConId"/>.</param> /// <param name="ratio">Select the relative number of contracts for the leg you are constructing. See property <see cref="ComboLeg.Ratio"/>.</param> /// <param name="action">The side (buy or sell) for the leg you are constructing. See property <see cref="ComboLeg.Action"/></param> /// <param name="exchange">The exchange to which the complete combination order will be routed. See property <see cref="ComboLeg.Exchange"/>.</param> /// <param name="openClose">Specifies whether the order is an open or close order. Retail customers must use <see cref="ComboOpenClose.Same"/>. See property <see cref="ComboLeg.OpenClose"/></param> /// <param name="shortSaleSlot">ShortSaleSlot of Third Party requires DesignatedLocation to be specified. Non-empty DesignatedLocation values for all other cases will cause orders to be rejected. See Property <see cref="ComboLeg.ShortSaleSlot"/></param> /// <param name="designatedLocation">Use only when shortSaleSlot value = 2. See Property <see cref="ComboLeg.DesignatedLocation"/></param> public ComboLeg(int conId, int ratio, ActionSide action, String exchange, ComboOpenClose openClose, ShortSaleSlot shortSaleSlot, string designatedLocation) : this(conId, ratio, action, exchange, openClose, shortSaleSlot, designatedLocation, -1) { }
public void ThenThereShouldBe(ActionSide side, Location location) => ThenThereShouldBe(side, "one", location);
/// <summary> /// Default Constructor /// </summary> public ExecutionFilter() { securityType = SecurityType.Undefined; side = ActionSide.Undefined; }
private static IEnumerable <GameAction> AllMergeMoveSplit(State currentState, ActionSide side) { var sideIsRed = side == ActionSide.Red; var blueWrap = side == ActionSide.Red ? Movement.Blue.CanWrap : Movement.Blue.CannotWrap; var redWrap = side == ActionSide.Blue ? Movement.Red.CanWrap : Movement.Red.CannotWrap; foreach (var myPieceLocation in State.AllBoardLocations.Where(loc => currentState[loc].RedPiece() == sideIsRed)) { var stackSize = currentState[myPieceLocation].GetSize(); foreach (var direction in Movement.AllMoves) { var location = myPieceLocation; for (var i = 1; i <= stackSize; i++) { location = direction(location, blueWrap, redWrap, Movement.UnmarkedEdges.CannotWrap); if (location == Location.Undefined || currentState[location].IsBlock()) { break; } if (currentState[location].GetSide(side == ActionSide.Blue, side == ActionSide.Red, true)) { yield return(new GameMoveAction { Side = side, Location = myPieceLocation, Target = location }); } else { yield return(new GameMergeAction { Side = side, Location = myPieceLocation, Target = location }); } for (var partialStack = i; partialStack < stackSize; partialStack++) { yield return(new GameSplitAction { Side = side, Location = myPieceLocation, Target = location, Size = partialStack }); } } } } }
public static bool OrderSideToActionSide(OrderSide orderside, out ActionSide action) { action = ActionSide.Undefined; switch (orderside) { case OrderSide.Buy: action = ActionSide.Buy; break; case OrderSide.Sell: action = ActionSide.Sell; break; default: return false; } return true; }
public void WhenIMovePointsDirection(ActionSide side, Location from, string distance, string direction) { Assert.NotNull(_context.BoardState, "Board State has not been initialized."); var distanceInt = CommonSteps.ParseWordNumber(distance); Movement.Mover directionFunc; switch (direction.ToLower().Trim()) { case "north": directionFunc = Movement.North; break; case "south": directionFunc = Movement.South; break; case "northeast": case "north-east": case "north east": directionFunc = Movement.NorthEast; break; case "northwest": case "north-west": case "north west": directionFunc = Movement.NorthWest; break; case "southeast": case "south-east": case "south east": directionFunc = Movement.SouthEast; break; case "southwest": case "south-west": case "south west": directionFunc = Movement.SouthWest; break; default: throw new ArgumentOutOfRangeException(nameof(direction), direction, "Was not a recognizable movement direction."); } var canPassRedWall = side == ActionSide.Blue ? Movement.Red.CanWrap : Movement.Red.CannotWrap; var canPassBlueWall = side == ActionSide.Red ? Movement.Blue.CanWrap : Movement.Blue.CannotWrap; var to = from; for (var i = 0; i < distanceInt; i++) { var next = directionFunc(to, canPassBlueWall, canPassRedWall, Movement.UnmarkedEdges.CannotWrap); if (!Movement.IsValidLocation(next)) { _context.LastMessage = $"Unable to reach point {i + 1} {direction} from {to} (starting from {from})"; Console.WriteLine(_context.LastMessage); return; } to = next; } var action = new GameMoveAction { Location = from, Side = side, Target = to }; TryApplyAction(action, from, to); }