/// <summary> /// Creates a <see cref="Octgn.Play.Card"/> from a <see cref="Octgn.DataNew.Entities.ICard"/> and stores its <see cref="Octgn.Play.CardIdentity"/> /// </summary> /// <param name="card"></param> /// <param name="player"></param> /// <returns></returns> public static Play.Card ToPlayCard(this ICard card, Play.Player player) { ulong key = card.GenerateKey(); int id = card.GenerateCardId(); var retCard = new Play.Card(player, id, key, Program.GameEngine.Definition.GetCardById(card.Id), true); return retCard; }
public void ActCanSetPlay() { var target = new Act(); Assert.IsNull(target.Play); var play = new Play(); target.Play = play; Assert.AreEqual(play, target.Play); }
public void TestSetPlayedSquare() { TicTacToe game = new TicTacToe("Player1", "Player2"); game.SetPlayedSquare(0, "Player1"); game.SetPlayedSquare(8, "Player2"); Play[] temp = new Play[9] { Play.Player1, 0, 0, 0, 0, 0, 0, 0, Play.Player2 }; CollectionAssert.AreEqual(game.GameBoard, temp); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); _GameMenu = new Menu(this.Content); _Play = new Play(this.Content); _Track1 = new Track1(this.Content, _Graphics); _OptionsMenu = new MenuOptions(this.Content); _CreditsMenu = new MenuCredits(this.Content); // TODO: use this.Content to load your game content here }
public PlayResult DoPlay(Play first, Play second) { if (first == second) return PlayResult.Tie; int nfirst = (int)first; int nsecond = (int)second; if (nsecond == (nfirst + 1) % 5 || nsecond == (nfirst + 2) % 5) return PlayResult.SecondPlayer; return PlayResult.FirstPlayer; }
/// <summary> /// Adds a play to <see cref="squaresList"/>. The play is not scored. /// </summary> /// <param name="play">The <see cref="Play"/> to be added to the <see cref="Board"/>.</param> public void AddPlayToBoard(Play play) { if (!this.PlayIsValid(play)) { throw new InvalidPlayException(); } for (int i = 0; i < play.GetParallelListLength(); ++i) { this.boardGrid[play.GetCoordinateX(i), play.GetCoordinateY(i)].InsertLetterTile(play.GetLetterTile(i)); } this.lastPlay = play; this.lastPlayIsNull = false; }
/// <summary> /// Draws the Game board for the user /// </summary> /// <param name="board">The list containing the TicTacToe board and the status of each square on the board</param> public void DrawGameBoard(Play[] board) { Console.Clear(); //Draws the squares of the TicTacToe board for (int i = 0; i < board.Length; i++) { if (board[i].Equals(Play.NotPlayed)) { Console.Write("_{0}_|", i + 1); } else if (board[i].Equals(Play.Player1)) { Console.Write("_X_|"); board[i] = Play.Player1; } else { Console.Write("_O_|"); board[i] = Play.Player2; } if(i%3 == 2) Console.WriteLine("\n"); } }
public void AddPlay(Play play) { playsSelection.AddPlay(play); timeline.AddPlay(play); timeline.QueueDraw(); }
public static Board.State[,] Play(Board.State[,] Last) { Board.State[,] ReturnState; List <Node> FoundNode = Node.Neighbourhood[GetLevel(Last)]; List <Node> Plays = new List <Node>(); int rot = 0; int mir = 0; foreach (Node Play in FoundNode) { if (Play.BoardsEqual(Last, out rot, out mir)) { Plays = new List <Node>(Play.Children); break; } } Node Selected = new Node(); FoundNode = new List <Node>(Plays); DiscardLosing(); GetWin(); if (Selected.Win != Board.State.P2) { Selected = FindTrap(); } if (!Plays.Contains(Selected)) { if (Plays.Count != 0) { Selected = Plays.OrderBy(o => o.Value).Last(); Console.WriteLine("Picking Last, " + Selected.Value); } else { Selected = FoundNode.Last(); } } //Restore to our original orientation and mirror Selected.Rotate(rot); Selected.Unmirror(mir); ReturnState = Selected.Board; return(ReturnState); //-------------------------------- //AI actions //Finds if one of the possible plays leads to a perfect win. Play is the AI play, SubPlay is the Player Play. If a play has all player plays lead to AI win, we can return that. Node FindTrap() { //we should expand this to find more traps hidden in our tree foreach (Node Play in Plays) { foreach (Node SubPlay in Play.Children) { bool Trap = true; foreach (Node OurPlay in SubPlay.Children) { if (SubPlay.Win != Board.State.P2) { Trap = false; break; } } if (Trap) { return(Play); } } } return(new Node()); } void DiscardLosing() { List <Node> Remove = new List <Node>(); foreach (Node a in Plays) { foreach (Node q in a.Children) { if (q.Win == Board.State.P1) { Remove.Add(a); } } } Plays = Plays.Except(Remove).ToList(); } void GetWin() { Node q = Plays.Find(o => o.Win == Board.State.P2); if (q != null) { Selected = q; } } }
/// <summary> /// Using this. Saving the play /// </summary> /// <param name="playname"></param> void SavingPlay(InputField playname) { var play = new Play(); formationCounter = allFormations.AllFormmations.Count; play.PlayName = playname.text; play.PlayID = allFormations.AllFormmations[formationCounter - 1].FormationID; var players = FindObjectsOfType <SinglePlayer>(); playsCounter = allFormations.AllFormmations[formationCounter - 1].LinkedPlaysWithFormation.Count; if (allFormations.AllFormmations[formationCounter - 1].LinkedPlaysWithFormation[playsCounter - 1].PlayName == playname.text) { UIManager.Instance.SelectTextType("Play with this name already exists, please choose different name", "warning", 2f); Debug.Log("play like this already exists"); } else { //adding this play because there isn't a play with this name allFormations.AllFormmations[formationCounter - 1].LinkedPlaysWithFormation.Add(play); } if (players != null) { foreach (var item in players) { item.Populate(formationCounter - 1, playsCounter - 1); } } playsNamesHolder.PlaysNamesHolder.Add(play.PlayName); formationCounter += 1; StartCoroutine(LateSaveEverything()); //if (!playsNamesHolder.PlaysNamesHolder.Contains(playname.text)) //{ // if (playname.text == "") // { // var play = new Play(); // formationCounter = allFormations.AllFormmations.Count; // play.PlayName = allFormations.AllFormmations[formationCounter - 1].FormationName + " Formation"; // play.PlayID = allFormations.AllFormmations[formationCounter - 1].FormationID; // allFormations.AllFormmations[formationCounter - 1].LinkedPlaysWithFormation.Add(play); // var players = FindObjectsOfType<SinglePlayer>(); // playsCounter = allFormations.AllFormmations[formationCounter - 1].LinkedPlaysWithFormation.Count; // if (players != null) // { // foreach (var item in players) // { // item.Populate(formationCounter - 1, playsCounter - 1); // } // } // playsNamesHolder.PlaysNamesHolder.Add(play.PlayName); // formationCounter += 1; // StartCoroutine(LateSaveEverything()); // } // else // { // var play = new Play(); // formationCounter = allFormations.AllFormmations.Count; // play.PlayName = playname.text; // play.PlayID = allFormations.AllFormmations[formationCounter - 1].FormationID; // allFormations.AllFormmations[formationCounter - 1].LinkedPlaysWithFormation.Add(play); // var players = FindObjectsOfType<SinglePlayer>(); // playsCounter = allFormations.AllFormmations[formationCounter - 1].LinkedPlaysWithFormation.Count; // if (players != null) // { // foreach (var item in players) // { // item.Populate(formationCounter - 1, playsCounter - 1); // } // } // playsNamesHolder.PlaysNamesHolder.Add(play.PlayName); // formationCounter += 1; // StartCoroutine(LateSaveEverything()); // } //} //else //{ // UIManager.Instance.SelectTextType("Play with this name already exists, please choose different name", "warning", 2f); //} //var play = new Play(); //play.PlayName = playname.text; //formationCounter = allFormations.AllFormmations.Count; //play.PlayID = allFormations.AllFormmations[formationCounter - 1].FormationID; //allFormations.AllFormmations[formationCounter - 1].LinkedPlaysWithFormation.Add(play); //var players = FindObjectsOfType<SinglePlayer>(); //playsCounter = allFormations.AllFormmations[formationCounter - 1].LinkedPlaysWithFormation.Count; //if (players != null) //{ // foreach (var item in players) // { // item.Populate(formationCounter - 1, playsCounter - 1); // } //} //formationCounter += 1; //StartCoroutine(LateSaveEverything()); }
public ResetCommand(Play play) { _play = play; }
private static PerformanceCalculator CreatePerformanceCalculator(Performance aPerformance, Play aPlay) { return(aPlay.Type switch { "tragedy" => new TragedyCalculator(aPerformance, aPlay), "comedy" => new ComedyCalculator(aPerformance, aPlay), _ => throw new Exception($"Unknown type: {aPlay.Type}") });
public OPlayer(Play.Player player) { this.player = player; }
private Play SortMoves(GameState gamestate, Play play, List<Play> legal_plays, List<Move> forced_moves) { if (gamestate.Dice[0] != gamestate.Dice[1]) { // Both are on the bar, sort the enter which uses bigger die as first. if (play.Count == 2 && play[0].IsEnter && play[1].IsEnter && play[1].To < play[0].To) play.Reverse(); // Third condition avoids sequences where the second move is dependant on the first one if (play.Count == 2 && /*remove me when fixed*/ !play[0].IsEnter && !play[1].IsEnter && forced_moves.Count == 0 && gamestate.Board.PointCount(gamestate.PlayerOnRoll, play[1].From) > 0) { // Case where there are two moves and they share the same 'from' point, sort so that the one with bigger distance is first. if (play[0].From == play[1].From && play[0].Distance < play[1].Distance) play.Reverse(); // Chain move, instead of 3/1 6/3 make 6/3/1 else if (play[0].From == play[1].To) play.Reverse(); // Same as above already properly sorted. Don't do anything. This condition avoids it being passed below if the second play is a hit and being reversed. else if (play[1].From == play[0].To) ; // If only one is a hit, greedily sort it as the first move else if (play[1].HasHits && !play[0].HasHits) play.Reverse(); else if (!play[0].HasHits && play[1].HasHits) play.Reverse(); else { } } } else { /*if (play.Count == 4) { }*/ } return play; }
/// <summary> /// Normally a <pre>video</pre> element doesn't have a <pre>change</pre> event. /// We force one and a use it as a proxy for all the Media Events. /// </summary> /// <param name="args">The event args - Value contains our JSON</param> protected virtual void OnChange(ChangeEventArgs args) { var ThisEvent = args?.Value?.ToString(); VideoEventData videoData = new VideoEventData(); try { videoData = JsonSerializer.Deserialize <VideoEventData>(ThisEvent, serializationOptions); } catch (Exception ex) { LoggerFactory .CreateLogger(nameof(VideoExComponentBase)) .LogError(ex, "Failed to convert the JSON: {0}", ThisEvent); } switch (videoData.EventName) { case VideoEvents.Abort: Abort?.Invoke(videoData.State); AbortEvent.InvokeAsync(videoData.State); break; case VideoEvents.CanPlay: CanPlay?.Invoke(videoData.State); CanPlayEvent.InvokeAsync(videoData.State); break; case VideoEvents.CanPlayThrough: CanPlayThrough?.Invoke(videoData.State); CanPlayThroughEvent.InvokeAsync(videoData.State); break; case VideoEvents.DurationChange: DurationChange?.Invoke(videoData.State); DurationChangeEvent.InvokeAsync(videoData.State); break; case VideoEvents.Emptied: Emptied?.Invoke(videoData.State); EmptiedEvent.InvokeAsync(videoData.State); break; case VideoEvents.Ended: Ended?.Invoke(videoData.State); EndedEvent.InvokeAsync(videoData.State); break; case VideoEvents.Error: Error?.Invoke(videoData.State); ErrorEvent.InvokeAsync(videoData.State); break; case VideoEvents.LoadedData: LoadedData?.Invoke(videoData.State); LoadedDataEvent.InvokeAsync(videoData.State); break; case VideoEvents.LoadedMetadata: LoadedMetadata?.Invoke(videoData.State); LoadedMetadataEvent.InvokeAsync(videoData.State); break; case VideoEvents.LoadStart: LoadStart?.Invoke(videoData.State); LoadStartEvent.InvokeAsync(videoData.State); break; case VideoEvents.Pause: Pause?.Invoke(videoData.State); PauseEvent.InvokeAsync(videoData.State); break; case VideoEvents.Play: Play?.Invoke(videoData.State); PlayEvent.InvokeAsync(videoData.State); break; case VideoEvents.Playing: Playing?.Invoke(videoData.State); PlayingEvent.InvokeAsync(videoData.State); break; case VideoEvents.Progress: Progress?.Invoke(videoData.State); ProgressEvent.InvokeAsync(videoData.State); break; case VideoEvents.RateChange: RateChange?.Invoke(videoData.State); RateChangeEvent.InvokeAsync(videoData.State); break; case VideoEvents.Seeked: Seeking?.Invoke(videoData.State); SeekingEvent.InvokeAsync(videoData.State); break; case VideoEvents.Seeking: Seeking?.Invoke(videoData.State); SeekingEvent.InvokeAsync(videoData.State); break; case VideoEvents.Stalled: Stalled?.Invoke(videoData.State); StalledEvent.InvokeAsync(videoData.State); break; case VideoEvents.Suspend: Suspend?.Invoke(videoData.State); SuspendEvent.InvokeAsync(videoData.State); break; case VideoEvents.TimeUpdate: TimeUpdate?.Invoke(videoData.State); TimeUpdateEvent.InvokeAsync(videoData.State); break; case VideoEvents.VolumeChange: VolumeChange?.Invoke(videoData.State); VolumeChangeEvent.InvokeAsync(videoData.State); break; case VideoEvents.Waiting: Waiting?.Invoke(videoData.State); WaitingEvent.InvokeAsync(videoData.State); break; default: break; } // Here is our catch-all event handler call! EventFired?.Invoke(videoData); }
void Update() { // See whether formation contains this play. if (formations.ContainsKey(Formations.iformation.ToString())) { List<Play> temp = formations[Formations.iformation.ToString()]; SelectedOffensivePlay = temp[playNum]; //hack for selected play } }
public override void OnAuthenticated() { Play.CreateRoom(); }
public override void OnRoomCustomPropertiesUpdated(Hashtable updatedProperties) { Play.Log(updatedProperties.ToLog()); }
protected override void OnMessage(MessageEventArgs e) //유저로부터 메시지를 받은 경우 { lock (users) { Code code = JsonConvert.DeserializeObject <Code>(e.Data); switch (code.code) { case 2: //play Play play = JsonConvert.DeserializeObject <Play>(e.Data); if (!stage.SetStone(myState, play.m, play.n)) { oppenent.Send(e.Data); } else { End end = new End(); end.winner = myState; end.m = play.m; end.n = play.n; string str = JsonConvert.SerializeObject(end); Send(str); oppenent.Send(str); } break; case 5: //replay replay = true; if (oppenent.replay == true) { stage.ResetPan(); //setState PosState save = myState; myState = oppenent.myState; oppenent.myState = save; //setting start_op Start start = new Start(); start.state = oppenent.myState; string str = JsonConvert.SerializeObject(start); oppenent.Send(str); //setting start_this start.state = myState; str = JsonConvert.SerializeObject(start); Send(str); replay = false; oppenent.replay = false; } break; case 7: //giveup { GiveUp giveUp = new GiveUp(); giveUp.winner = oppenent.myState; string str = JsonConvert.SerializeObject(giveUp); Send(str); oppenent.Send(str); break; } } } }
public static InstructionCollection Parse(Stream input, long instructionsPosition) { var instructions = new SortedList <int, InstructionBase>(); using (var helper = new InstructionParseHelper(input, instructionsPosition)) { var reader = helper.GetReader(); while (helper.CanParse(instructions)) { //now reader the instructions var instructionPosition = helper.CurrentPosition; var type = reader.ReadByteAsEnum <InstructionType>(); var requireAlignment = InstructionAlignment.IsAligned(type); if (requireAlignment) { reader.Align(4); } InstructionBase instruction = null; var parameters = new List <Value>(); switch (type) { case InstructionType.ToNumber: instruction = new ToNumber(); break; case InstructionType.NextFrame: instruction = new NextFrame(); break; case InstructionType.Play: instruction = new Play(); break; case InstructionType.Stop: instruction = new Stop(); break; case InstructionType.Add: instruction = new Add(); break; case InstructionType.Subtract: instruction = new Subtract(); break; case InstructionType.Multiply: instruction = new Multiply(); break; case InstructionType.Divide: instruction = new Divide(); break; case InstructionType.Not: instruction = new Not(); break; case InstructionType.StringEquals: instruction = new StringEquals(); break; case InstructionType.Pop: instruction = new Pop(); break; case InstructionType.ToInteger: instruction = new ToInteger(); break; case InstructionType.GetVariable: instruction = new GetVariable(); break; case InstructionType.SetVariable: instruction = new SetVariable(); break; case InstructionType.StringConcat: instruction = new StringConcat(); break; case InstructionType.GetProperty: instruction = new GetProperty(); break; case InstructionType.SetProperty: instruction = new SetProperty(); break; case InstructionType.Trace: instruction = new Trace(); break; case InstructionType.Random: instruction = new RandomNumber(); break; case InstructionType.Delete: instruction = new Delete(); break; case InstructionType.Delete2: instruction = new Delete2(); break; case InstructionType.DefineLocal: instruction = new DefineLocal(); break; case InstructionType.CallFunction: instruction = new CallFunction(); break; case InstructionType.Return: instruction = new Return(); break; case InstructionType.Modulo: instruction = new Modulo(); break; case InstructionType.NewObject: instruction = new NewObject(); break; case InstructionType.InitArray: instruction = new InitArray(); break; case InstructionType.InitObject: instruction = new InitObject(); break; case InstructionType.TypeOf: instruction = new TypeOf(); break; case InstructionType.Add2: instruction = new Add2(); break; case InstructionType.LessThan2: instruction = new LessThan2(); break; case InstructionType.Equals2: instruction = new Equals2(); break; case InstructionType.ToString: instruction = new ToString(); break; case InstructionType.PushDuplicate: instruction = new PushDuplicate(); break; case InstructionType.GetMember: instruction = new GetMember(); break; case InstructionType.SetMember: instruction = new SetMember(); break; case InstructionType.Increment: instruction = new Increment(); break; case InstructionType.Decrement: instruction = new Decrement(); break; case InstructionType.CallMethod: instruction = new CallMethod(); break; case InstructionType.Enumerate2: instruction = new Enumerate2(); break; case InstructionType.EA_PushThis: instruction = new PushThis(); break; case InstructionType.EA_PushZero: instruction = new PushZero(); break; case InstructionType.EA_PushOne: instruction = new PushOne(); break; case InstructionType.EA_CallFunc: instruction = new CallFunc(); break; case InstructionType.EA_CallMethodPop: instruction = new CallMethodPop(); break; case InstructionType.BitwiseXOr: instruction = new BitwiseXOr(); break; case InstructionType.Greater: instruction = new Greater(); break; case InstructionType.EA_PushThisVar: instruction = new PushThisVar(); break; case InstructionType.EA_PushGlobalVar: instruction = new PushGlobalVar(); break; case InstructionType.EA_ZeroVar: instruction = new ZeroVar(); break; case InstructionType.EA_PushTrue: instruction = new PushTrue(); break; case InstructionType.EA_PushFalse: instruction = new PushFalse(); break; case InstructionType.EA_PushNull: instruction = new PushNull(); break; case InstructionType.EA_PushUndefined: instruction = new PushUndefined(); break; case InstructionType.GotoFrame: instruction = new GotoFrame(); parameters.Add(Value.FromInteger(reader.ReadInt32())); break; case InstructionType.GetURL: instruction = new GetUrl(); parameters.Add(Value.FromString(reader.ReadStringAtOffset())); parameters.Add(Value.FromString(reader.ReadStringAtOffset())); break; case InstructionType.SetRegister: instruction = new SetRegister(); parameters.Add(Value.FromInteger(reader.ReadInt32())); break; case InstructionType.ConstantPool: { instruction = new ConstantPool(); var count = reader.ReadUInt32(); var constants = reader.ReadFixedSizeArrayAtOffset <uint>(() => reader.ReadUInt32(), count); foreach (var constant in constants) { parameters.Add(Value.FromConstant(constant)); } } break; case InstructionType.GotoLabel: instruction = new GotoLabel(); parameters.Add(Value.FromString(reader.ReadStringAtOffset())); break; case InstructionType.DefineFunction2: { instruction = new DefineFunction2(); var name = reader.ReadStringAtOffset(); var nParams = reader.ReadUInt32(); var nRegisters = reader.ReadByte(); var flags = reader.ReadUInt24(); //list of parameter strings var paramList = reader.ReadFixedSizeListAtOffset <FunctionArgument>(() => new FunctionArgument() { Register = reader.ReadInt32(), Parameter = reader.ReadStringAtOffset(), }, nParams); parameters.Add(Value.FromString(name)); parameters.Add(Value.FromInteger((int)nParams)); parameters.Add(Value.FromInteger((int)nRegisters)); parameters.Add(Value.FromInteger((int)flags)); foreach (var param in paramList) { parameters.Add(Value.FromInteger(param.Register)); parameters.Add(Value.FromString(param.Parameter)); } //body size of the function parameters.Add(Value.FromInteger(reader.ReadInt32())); //skip 8 bytes reader.ReadUInt64(); } break; case InstructionType.PushData: { instruction = new PushData(); var count = reader.ReadUInt32(); var constants = reader.ReadFixedSizeArrayAtOffset <uint>(() => reader.ReadUInt32(), count); foreach (var constant in constants) { parameters.Add(Value.FromConstant(constant)); } } break; case InstructionType.BranchAlways: { instruction = new BranchAlways(); var offset = reader.ReadInt32(); parameters.Add(Value.FromInteger(offset)); helper.ReportBranchOffset(offset); } break; case InstructionType.GetURL2: instruction = new GetUrl2(); break; case InstructionType.DefineFunction: { instruction = new DefineFunction(); var name = reader.ReadStringAtOffset(); //list of parameter strings var paramList = reader.ReadListAtOffset <string>(() => reader.ReadStringAtOffset()); parameters.Add(Value.FromString(name)); parameters.Add(Value.FromInteger(paramList.Count)); foreach (var param in paramList) { parameters.Add(Value.FromString(param)); } //body size of the function parameters.Add(Value.FromInteger(reader.ReadInt32())); //skip 8 bytes reader.ReadUInt64(); } break; case InstructionType.BranchIfTrue: { instruction = new BranchIfTrue(); var offset = reader.ReadInt32(); parameters.Add(Value.FromInteger(offset)); helper.ReportBranchOffset(offset); } break; case InstructionType.GotoFrame2: instruction = new GotoFrame2(); parameters.Add(Value.FromInteger(reader.ReadInt32())); break; case InstructionType.EA_PushString: instruction = new PushString(); //the constant id that should be pushed parameters.Add(Value.FromString(reader.ReadStringAtOffset())); break; case InstructionType.EA_PushConstantByte: instruction = new PushConstantByte(); //the constant id that should be pushed parameters.Add(Value.FromConstant(reader.ReadByte())); break; case InstructionType.EA_GetStringVar: instruction = new GetStringVar(); parameters.Add(Value.FromString(reader.ReadStringAtOffset())); break; case InstructionType.EA_SetStringVar: instruction = new SetStringVar(); parameters.Add(Value.FromString(reader.ReadStringAtOffset())); break; case InstructionType.EA_GetStringMember: instruction = new GetStringMember(); parameters.Add(Value.FromString(reader.ReadStringAtOffset())); break; case InstructionType.EA_SetStringMember: instruction = new SetStringMember(); parameters.Add(Value.FromString(reader.ReadStringAtOffset())); break; case InstructionType.EA_PushValueOfVar: instruction = new PushValueOfVar(); //the constant id that should be pushed parameters.Add(Value.FromConstant(reader.ReadByte())); break; case InstructionType.EA_GetNamedMember: instruction = new GetNamedMember(); parameters.Add(Value.FromConstant(reader.ReadByte())); break; case InstructionType.EA_CallNamedFuncPop: instruction = new CallNamedFuncPop(); parameters.Add(Value.FromConstant(reader.ReadByte())); break; case InstructionType.EA_CallNamedFunc: instruction = new CallNamedFunc(); parameters.Add(Value.FromConstant(reader.ReadByte())); break; case InstructionType.EA_CallNamedMethodPop: instruction = new CallNamedMethodPop(); parameters.Add(Value.FromConstant(reader.ReadByte())); break; case InstructionType.EA_PushFloat: instruction = new PushFloat(); parameters.Add(Value.FromFloat(reader.ReadSingle())); break; case InstructionType.EA_PushByte: instruction = new PushByte(); parameters.Add(Value.FromInteger(reader.ReadByte())); break; case InstructionType.EA_PushShort: instruction = new PushShort(); parameters.Add(Value.FromInteger(reader.ReadUInt16())); break; case InstructionType.End: instruction = new End(); break; case InstructionType.EA_CallNamedMethod: instruction = new CallNamedMethod(); parameters.Add(Value.FromConstant(reader.ReadByte())); break; case InstructionType.Var: instruction = new Var(); break; case InstructionType.EA_PushRegister: instruction = new PushRegister(); parameters.Add(Value.FromInteger(reader.ReadByte())); break; case InstructionType.EA_PushConstantWord: instruction = new PushConstantWord(); parameters.Add(Value.FromConstant(reader.ReadUInt16())); break; case InstructionType.EA_CallFuncPop: instruction = new CallFunctionPop(); break; case InstructionType.StrictEqual: instruction = new StrictEquals(); break; default: throw new InvalidDataException("Unimplemented bytecode instruction:" + type.ToString()); } if (instruction != null) { instruction.Parameters = parameters; instructions.Add(instructionPosition, instruction); } } } return(new InstructionCollection(instructions)); }
// Computer move private void button2_Click(object sender, EventArgs e) { Moves = new ArrayList(); for (int i = 0; i < 9; i++) { if (Game[i] == '-') // possible move for '0' { string Temp = Game.Substring(0, i) + 'O' + Game.Substring(i + 1); bool Found = false; foreach (string State in Library) { if (Temp == State.Substring(0, 9)) // match found in knowledge database { Moves.Add(new Play(i, State.Substring(10, 1))); Found = true; } } // end foreach if (!Found) { Moves.Add(new Play(i, "U")); } } } // end for // Show moves listBox1.Items.Clear(); foreach (Play move in Moves) { listBox1.Items.Add(move); } // Check if all plays are not unknown - if so, then add prior moves to library bool AllOutcomesKnown = true; foreach (Play p in Moves) { if (p.Outcome == "U") { AllOutcomesKnown = false; } } if (AllOutcomesKnown) { for (int i = 0; i < 9; i++) { if (Game[i] == 'X') { Library.Add(Game.Substring(0, i) + '-' + Game.Substring(i + 1) + " L"); } } } // Choose next "best" move in order Play m = (Play)Moves[0]; foreach (Play p in Moves) { if (Better(p.Outcome, m.Outcome)) { m = p; // p > m } } Game = Game.Substring(0, m.Position) + 'O' + Game.Substring(m.Position + 1); DrawGame(pictureBox1.Width); } // end method button2_Click
/// <summary> /// Gets a list of all the words created by a given play. /// </summary> /// <param name="play">The play being checked.</param> /// <returns>The list of words created by the play.</returns> public List<string> GetWordsInPlay(Play play) { List<string> words = new List<string>(); bool isVerticalPlay; // Make sure that all of the LetterTiles in the play are already on the board. for (int i = 0; i < play.GetParallelListLength(); ++i) { if (this.boardGrid[play.GetCoordinateX(i), play.GetCoordinateY(i)].IsEmpty()) { throw new InvalidPlayException(); } if (!this.boardGrid[play.GetCoordinateX(i), play.GetCoordinateY(i)].ContainedLetterTile.Equals(play.GetLetterTile(i))) { throw new InvalidPlayException(); } } if (play.GetParallelListLength() == 1 || play.GetCoordinateX(0) == play.GetCoordinateX(1)) { isVerticalPlay = true; } else { isVerticalPlay = false; } int x = play.GetCoordinateX(0); int y = play.GetCoordinateY(0); if (isVerticalPlay) { int topOfWord = y; int midX = x; StringBuilder wordBuilder = new StringBuilder(); // Get to the top of the vertical word. while (topOfWord > 0) { if (this.boardGrid[x, topOfWord - 1].IsEmpty()) { break; } else { --topOfWord; } } while (topOfWord <= 14) { if (this.boardGrid[x, topOfWord].IsEmpty()) { break; } else { wordBuilder.Append(this.boardGrid[x, topOfWord].ContainedLetterTile.LetterValue); ++topOfWord; } } if (wordBuilder.ToString().Length > 1) { words.Add(wordBuilder.ToString()); } wordBuilder.Clear(); // Get all the words that branch off from that word. for (int i = 0; i < play.GetParallelListLength(); ++i) { int leftOfWord = play.GetCoordinateX(i); // Go to the left end of the word while (leftOfWord > 0) { if (this.boardGrid[leftOfWord - 1, play.GetCoordinateY(i)].IsEmpty()) { break; } else { --leftOfWord; } } // Read rightward until the word ends. while (leftOfWord <= 14) { if (this.boardGrid[leftOfWord, play.GetCoordinateY(i)].IsEmpty()) { break; } else { wordBuilder.Append(this.boardGrid[leftOfWord, play.GetCoordinateY(i)].ContainedLetterTile.LetterValue); ++leftOfWord; } } if (wordBuilder.ToString().Length > 1) { words.Add(wordBuilder.ToString()); } wordBuilder.Clear(); } } else { int leftOfWord = x; int midY = y; StringBuilder wordBuilder = new StringBuilder(); // Get to the top of the vertical word. while (leftOfWord > 0) { if (this.boardGrid[leftOfWord - 1, y].IsEmpty()) { break; } else { --leftOfWord; } } while (leftOfWord <= 14) { if (this.boardGrid[leftOfWord, y].IsEmpty()) { break; } else { wordBuilder.Append(this.boardGrid[leftOfWord, y].ContainedLetterTile.LetterValue); ++leftOfWord; } } if (wordBuilder.ToString().Length > 1) { words.Add(wordBuilder.ToString()); } wordBuilder.Clear(); // Get all the words that branch off from that word. for (int i = 0; i < play.GetParallelListLength(); ++i) { int topOfWord = play.GetCoordinateY(i); // Go to the left end of the word while (topOfWord > 0) { if (this.boardGrid[play.GetCoordinateX(i), topOfWord - 1].IsEmpty()) { break; } else { --topOfWord; } } // Read rightward until the word ends. while (topOfWord <= 14) { if (this.boardGrid[play.GetCoordinateX(i), topOfWord].IsEmpty()) { break; } else { wordBuilder.Append(this.boardGrid[play.GetCoordinateX(i), topOfWord].ContainedLetterTile.LetterValue); ++topOfWord; } } if (wordBuilder.ToString().Length > 1) { words.Add(wordBuilder.ToString()); } wordBuilder.Clear(); } } return words; }
// Use this for initialization void Start() { #region Create playbook formations = new Dictionary<string, List<Play>>(2); #endregion #region Create plays // first play Play _p1 = new Play(); /* /positions are in screen space from 0.0 to 1.0, where 0.0 x and 0.0 y are top left and 1.0 x and 1.0 y is bottom right */ #region Iformation _p1.VectorPosition = new Vector3[11]; _p1.VectorPosition[0] = new Vector3( 0.5f,0.6f,0);//QB _p1.VectorPosition[1] = new Vector3( 0.5f,0.7f,0);//FB _p1.VectorPosition[2] = new Vector3( 0.5f,.8f,0);//HB _p1.VectorPosition[3] = new Vector3( 0.5f,0.5f,0);//C _p1.VectorPosition[4] = new Vector3(0.45f,0.5f,0);//G _p1.VectorPosition[5] = new Vector3(0.55f,0.5f,0);//G _p1.VectorPosition[6] = new Vector3( 0.6f,0.5f,0);//T _p1.VectorPosition[7] = new Vector3( 0.4f,0.5f,0);//T _p1.VectorPosition[8] = new Vector3(0.65f,0.5f,0);//TE _p1.VectorPosition[9] = new Vector3(0.15f,0.5f,0);//WR _p1.VectorPosition[10] = new Vector3(0.85f,.55f,0);//WR _p1.PlayerPositions = new string[11]; _p1.PlayerPositions[0] = "QB"; _p1.PlayerPositions[1] = "FB"; _p1.PlayerPositions[2] = "HB"; _p1.PlayerPositions[3] = "C"; _p1.PlayerPositions[4] = "G"; _p1.PlayerPositions[5] = "G"; _p1.PlayerPositions[6] = "T"; _p1.PlayerPositions[7] = "T"; _p1.PlayerPositions[8] = "TE"; _p1.PlayerPositions[9] = "WR"; _p1.PlayerPositions[10] = "WR"; _p1.Routes = new Routes[11]; _p1.Routes[0] = Routes.qb; _p1.Routes[1] = Routes.passblock; _p1.Routes[2] = Routes.flat; _p1.Routes[3] = Routes.post; _p1.Routes[4] = Routes.passblock; _p1.Routes[5] = Routes.passblock; _p1.Routes[6] = Routes.passblock; _p1.Routes[7] = Routes.passblock; _p1.Routes[8] = Routes.passblock; _p1.Routes[9] = Routes.passblock; _p1.Routes[10] = Routes.passblock; //second play Play _p2 = new Play(); _p2.VectorPosition = new Vector3[7]; _p2.VectorPosition = _p1.VectorPosition; _p2.PlayerPositions = new string[7]; _p2.PlayerPositions = _p1.PlayerPositions; _p2.Routes = new Routes[7]; _p2.Routes[0] = Routes.qb; _p2.Routes[1] = Routes.hbrun; _p2.Routes[2] = Routes.flat; _p2.Routes[3] = Routes.post; _p2.Routes[4] = Routes.runblock; _p2.Routes[5] = Routes.runblock; _p2.Routes[6] = Routes.runblock; //third play Play _p3 = new Play(); _p3.VectorPosition = new Vector3[7]; _p3.VectorPosition = _p1.VectorPosition; _p3.PlayerPositions = new string[7]; _p3.PlayerPositions = _p1.PlayerPositions; _p3.Routes = new Routes[7]; _p3.Routes[0] = Routes.runblock; _p3.Routes[1] = Routes.runblock; _p3.Routes[2] = Routes.streak; _p3.Routes[3] = Routes.runblock; _p3.Routes[4] = Routes.runblock; _p3.Routes[5] = Routes.runblock; _p3.Routes[6] = Routes.runblock; #endregion #region iformationStrong Play _IStrong1 = new Play(); _IStrong1.VectorPosition = new Vector3[11]; _IStrong1.VectorPosition[0] = new Vector3( 0.5f,0.6f,0);//QB _IStrong1.VectorPosition[1] = new Vector3( 0.55f,0.7f,0);//FB _IStrong1.VectorPosition[2] = new Vector3( 0.5f,0.8f,0);//HB _IStrong1.VectorPosition[3] = new Vector3( 0.5f,0.5f,0);//C _IStrong1.VectorPosition[4] = new Vector3(0.45f,0.5f,0);//G _IStrong1.VectorPosition[5] = new Vector3(0.55f,0.5f,0);//G _IStrong1.VectorPosition[6] = new Vector3( 0.6f,0.5f,0);//T _IStrong1.VectorPosition[7] = new Vector3( 0.4f,0.5f,0);//T _IStrong1.VectorPosition[8] = new Vector3(0.65f,0.5f,0);//TE _IStrong1.VectorPosition[9] = new Vector3(0.15f,0.5f,0);//WR _IStrong1.VectorPosition[10] = new Vector3(0.85f,.55f,0);//WR _IStrong1.PlayerPositions = new string[11]; _IStrong1.PlayerPositions[0] = "QB"; _IStrong1.PlayerPositions[1] = "FB"; _IStrong1.PlayerPositions[2] = "HB"; _IStrong1.PlayerPositions[3] = "C"; _IStrong1.PlayerPositions[4] = "G"; _IStrong1.PlayerPositions[5] = "G"; _IStrong1.PlayerPositions[6] = "T"; _IStrong1.PlayerPositions[7] = "T"; _IStrong1.PlayerPositions[8] = "TE"; _IStrong1.PlayerPositions[9] = "WR"; _IStrong1.PlayerPositions[10] = "WR"; _IStrong1.Routes = new Routes[11]; _IStrong1.Routes[0] = Routes.qb; _IStrong1.Routes[1] = Routes.passblock; _IStrong1.Routes[2] = Routes.flat; _IStrong1.Routes[3] = Routes.post; _IStrong1.Routes[4] = Routes.passblock; _IStrong1.Routes[5] = Routes.passblock; _IStrong1.Routes[6] = Routes.passblock; _IStrong1.Routes[7] = Routes.passblock; _IStrong1.Routes[8] = Routes.passblock; _IStrong1.Routes[9] = Routes.passblock; _IStrong1.Routes[10] = Routes.passblock; #endregion #region ShotgunMax Play _ShotGunMax1 = new Play(); _ShotGunMax1.VectorPosition = new Vector3[11]; _ShotGunMax1.VectorPosition[0] = new Vector3( 0.5f,0.65f,0);//QB _ShotGunMax1.VectorPosition[1] = new Vector3( 0.45f,0.65f,0);//FB _ShotGunMax1.VectorPosition[2] = new Vector3( 0.55f,.65f,0);//HB _ShotGunMax1.VectorPosition[3] = new Vector3( 0.5f,0.5f,0);//C _ShotGunMax1.VectorPosition[4] = new Vector3(0.45f,0.5f,0);//G _ShotGunMax1.VectorPosition[5] = new Vector3(0.55f,0.5f,0);//G _ShotGunMax1.VectorPosition[6] = new Vector3( 0.6f,0.5f,0);//T _ShotGunMax1.VectorPosition[7] = new Vector3( 0.4f,0.5f,0);//T _ShotGunMax1.VectorPosition[8] = new Vector3(0.65f,0.5f,0);//TE _ShotGunMax1.VectorPosition[9] = new Vector3(0.15f,0.5f,0);//WR _ShotGunMax1.VectorPosition[10] = new Vector3(0.85f,.55f,0);//WR _ShotGunMax1.PlayerPositions = new string[11]; _ShotGunMax1.PlayerPositions[0] = "QB"; _ShotGunMax1.PlayerPositions[1] = "FB"; _ShotGunMax1.PlayerPositions[2] = "HB"; _ShotGunMax1.PlayerPositions[3] = "C"; _ShotGunMax1.PlayerPositions[4] = "G"; _ShotGunMax1.PlayerPositions[5] = "G"; _ShotGunMax1.PlayerPositions[6] = "T"; _ShotGunMax1.PlayerPositions[7] = "T"; _ShotGunMax1.PlayerPositions[8] = "TE"; _ShotGunMax1.PlayerPositions[9] = "WR"; _ShotGunMax1.PlayerPositions[10] = "WR"; _ShotGunMax1.Routes = new Routes[11]; _ShotGunMax1.Routes[0] = Routes.qb; _ShotGunMax1.Routes[1] = Routes.passblock; _ShotGunMax1.Routes[2] = Routes.flat; _ShotGunMax1.Routes[3] = Routes.post; _ShotGunMax1.Routes[4] = Routes.passblock; _ShotGunMax1.Routes[5] = Routes.passblock; _ShotGunMax1.Routes[6] = Routes.passblock; _ShotGunMax1.Routes[7] = Routes.passblock; _ShotGunMax1.Routes[8] = Routes.passblock; _ShotGunMax1.Routes[9] = Routes.passblock; _ShotGunMax1.Routes[10] = Routes.passblock; #endregion #region iformationWeak Play _IWeak1 = new Play(); _IWeak1.VectorPosition = new Vector3[11]; _IWeak1.VectorPosition[0] = new Vector3( 0.5f,0.6f,0);//QB _IWeak1.VectorPosition[1] = new Vector3( 0.45f,0.7f,0);//FB _IWeak1.VectorPosition[2] = new Vector3( 0.5f,0.8f,0);//HB _IWeak1.VectorPosition[3] = new Vector3( 0.5f,0.5f,0);//C _IWeak1.VectorPosition[4] = new Vector3(0.45f,0.5f,0);//G _IWeak1.VectorPosition[5] = new Vector3(0.55f,0.5f,0);//G _IWeak1.VectorPosition[6] = new Vector3( 0.6f,0.5f,0);//T _IWeak1.VectorPosition[7] = new Vector3( 0.4f,0.5f,0);//T _IWeak1.VectorPosition[8] = new Vector3(0.65f,0.5f,0);//TE _IWeak1.VectorPosition[9] = new Vector3(0.15f,0.5f,0);//WR _IWeak1.VectorPosition[10] = new Vector3(0.85f,.55f,0);//WR _IWeak1.PlayerPositions = new string[11]; _IWeak1.PlayerPositions[0] = "QB"; _IWeak1.PlayerPositions[1] = "FB"; _IWeak1.PlayerPositions[2] = "HB"; _IWeak1.PlayerPositions[3] = "C"; _IWeak1.PlayerPositions[4] = "G"; _IWeak1.PlayerPositions[5] = "G"; _IWeak1.PlayerPositions[6] = "T"; _IWeak1.PlayerPositions[7] = "T"; _IWeak1.PlayerPositions[8] = "TE"; _IWeak1.PlayerPositions[9] = "WR"; _IWeak1.PlayerPositions[10] = "WR"; _IWeak1.Routes = new Routes[11]; _IWeak1.Routes[0] = Routes.qb; _IWeak1.Routes[1] = Routes.passblock; _IWeak1.Routes[2] = Routes.flat; _IWeak1.Routes[3] = Routes.post; _IWeak1.Routes[4] = Routes.passblock; _IWeak1.Routes[5] = Routes.passblock; _IWeak1.Routes[6] = Routes.passblock; _IWeak1.Routes[7] = Routes.passblock; _IWeak1.Routes[8] = Routes.passblock; _IWeak1.Routes[9] = Routes.passblock; _IWeak1.Routes[10] = Routes.passblock; #endregion #region Pistol Play _Pistol1 = new Play(); _Pistol1.VectorPosition = new Vector3[11]; _Pistol1.VectorPosition[0] = new Vector3( 0.5f,0.6f,0);//QB _Pistol1.VectorPosition[1] = new Vector3( 0.25f,0.55f,0);//WR _Pistol1.VectorPosition[2] = new Vector3( 0.5f,.65f,0);//HB _Pistol1.VectorPosition[3] = new Vector3( 0.5f,0.5f,0);//C _Pistol1.VectorPosition[4] = new Vector3(0.45f,0.5f,0);//G _Pistol1.VectorPosition[5] = new Vector3(0.55f,0.5f,0);//G _Pistol1.VectorPosition[6] = new Vector3( 0.6f,0.5f,0);//T _Pistol1.VectorPosition[7] = new Vector3( 0.4f,0.5f,0);//T _Pistol1.VectorPosition[8] = new Vector3(0.65f,0.5f,0);//TE _Pistol1.VectorPosition[9] = new Vector3(0.15f,0.5f,0);//WR _Pistol1.VectorPosition[10] = new Vector3(0.85f,.55f,0);//WR _Pistol1.PlayerPositions = new string[11]; _Pistol1.PlayerPositions[0] = "QB"; _Pistol1.PlayerPositions[1] = "WR"; _Pistol1.PlayerPositions[2] = "HB"; _Pistol1.PlayerPositions[3] = "C"; _Pistol1.PlayerPositions[4] = "G"; _Pistol1.PlayerPositions[5] = "G"; _Pistol1.PlayerPositions[6] = "T"; _Pistol1.PlayerPositions[7] = "T"; _Pistol1.PlayerPositions[8] = "TE"; _Pistol1.PlayerPositions[9] = "WR"; _Pistol1.PlayerPositions[10] = "WR"; _Pistol1.Routes = new Routes[11]; _Pistol1.Routes[0] = Routes.qb; _Pistol1.Routes[1] = Routes.passblock; _Pistol1.Routes[2] = Routes.flat; _Pistol1.Routes[3] = Routes.post; _Pistol1.Routes[4] = Routes.passblock; _Pistol1.Routes[5] = Routes.passblock; _Pistol1.Routes[6] = Routes.passblock; _Pistol1.Routes[7] = Routes.passblock; _Pistol1.Routes[8] = Routes.passblock; _Pistol1.Routes[9] = Routes.passblock; _Pistol1.Routes[10] = Routes.passblock; #endregion #endregion #region collect all plays for particular formation allPlays = new List<Play>(); allPlays.Add(_p1);//play index 0 allPlays.Add(_p2); allPlays.Add(_p3); allPlays.Add(_IStrong1); allPlays.Add(_ShotGunMax1); allPlays.Add(_IWeak1);//play index 5 allPlays.Add(_Pistol1); #endregion #region Add plays to formation //loop throught all formations and add them into the formatiosn dictionary if(!formations.ContainsKey(Formations.iformation.ToString())) { formations.Add(Formations.iformation.ToString(), allPlays); } #endregion // See whether formation contains this play. if (formations.ContainsKey(Formations.iformation.ToString())) { List<Play> temp = formations[Formations.iformation.ToString()]; SelectedOffensivePlay = temp[playNum]; //hack for selected play } }
/// <summary> /// Scores a <see cref="Play"/> that was already added to the board. /// </summary> /// <param name="play">The <see cref="Play"/> to be scored.</param> /// <param name="shouldRemoveMultipliers">Tells whether the <see cref="GameBoardSquare"/>s which are being filled by /// the <see cref="LetterTile"/>s in play should have their score multipliers set to 1.</param> /// <returns>The score of a <see cref="Play"/> that was already added to the board.</returns> public int ScorePlay(Play play, bool shouldRemoveMultipliers) { // Make sure the play is already on the board. for (int i = 0; i < play.GetParallelListLength(); ++i) { int x = play.GetCoordinateX(i); int y = play.GetCoordinateY(i); if (!this.boardGrid[x, y].ContainedLetterTile.Equals(play.GetLetterTile(i))) { throw new InvalidPlayException(); } } int totalPoints = 0; // If the play consists of only one LetterTile, score vertically and horizontally around it. if (play.GetParallelListLength() == 1) { totalPoints += this.ScoreOneHorizontalWord(play.GetCoordinateX(0), play.GetCoordinateY(0)); totalPoints += this.ScoreOneVerticalWord(play.GetCoordinateX(0), play.GetCoordinateY(0)); } else if (play.GetCoordinateY(0) == play.GetCoordinateY(1)) { // Otherwise, if the play is a horizontal play, score all of the vertical words that branch off from that // play, and then score the horizontal word in play. int horizontalWordMultiplier = 1; int horizontalWordPoints = 0; for (int i = 0; i < play.GetParallelListLength(); ++i) { horizontalWordMultiplier *= this.boardGrid[play.GetCoordinateX(i), play.GetCoordinateY(i)].WordMultiplier; } for (int i = 0; i < play.GetParallelListLength(); ++i) { totalPoints += this.ScoreOneVerticalWord(play.GetCoordinateX(i), play.GetCoordinateY(i)); horizontalWordPoints += this.ScoreOneTile(play.GetCoordinateX(i), play.GetCoordinateY(i)); } // Get the points from the adjacent squares to the left and right of the played letters. int minX = play.GetCoordinateX(0); int maxX = minX; for (int i = 0; i < play.GetParallelListLength(); ++i) { if (minX > play.GetCoordinateX(i)) { minX = play.GetCoordinateX(i); } if (maxX < play.GetCoordinateX(i)) { maxX = play.GetCoordinateX(i); } } // Go left. int count = 1; while (true) { if (minX - count < 0 || this.boardGrid[minX - count, play.GetCoordinateY(0)].IsEmpty()) { break; } else { horizontalWordPoints += this.ScoreOneTile(minX - count, play.GetCoordinateY(0)); ++count; } } // Go right. count = 1; while (true) { if (maxX + count > 14 || this.boardGrid[maxX + count, play.GetCoordinateY(0)].IsEmpty()) { break; } else { horizontalWordPoints += this.ScoreOneTile(maxX + count, play.GetCoordinateY(0)); ++count; } } // Check for gaps between letters in the play, and score them. List<int> coordsX = new List<int>(); for (int i = 0; i < play.GetParallelListLength(); ++i) { coordsX.Add(play.GetCoordinateX(i)); } coordsX.Sort(); count = 1; for (int i = 0; i < coordsX.Count - 1; ++i) { while (coordsX[i] + count < coordsX[i + 1]) { horizontalWordPoints += this.ScoreOneTile(coordsX[i] + count, play.GetCoordinateY(0)); ++count; } count = 1; } horizontalWordPoints *= horizontalWordMultiplier; totalPoints += horizontalWordPoints; } else { // Otherwise, if the play is a vertical play, score all of the horizontal words that branch off from that // play, and then score the vertical word in play. int verticalWordMultiplier = 1; int verticalWordPoints = 0; for (int i = 0; i < play.GetParallelListLength(); ++i) { verticalWordMultiplier *= this.boardGrid[play.GetCoordinateX(i), play.GetCoordinateY(i)].WordMultiplier; } for (int i = 0; i < play.GetParallelListLength(); ++i) { totalPoints += this.ScoreOneHorizontalWord(play.GetCoordinateX(i), play.GetCoordinateY(i)); verticalWordPoints += this.ScoreOneTile(play.GetCoordinateX(i), play.GetCoordinateY(i)); } // Get the points from the adjacent squares above and below the played letters. int minY = play.GetCoordinateY(0); int maxY = minY; for (int i = 0; i < play.GetParallelListLength(); ++i) { if (minY > play.GetCoordinateY(i)) { minY = play.GetCoordinateY(i); } if (maxY < play.GetCoordinateY(i)) { maxY = play.GetCoordinateY(i); } } // Go up. int count = 1; while (true) { if (minY - count < 0 || this.boardGrid[play.GetCoordinateX(0), minY - count].IsEmpty()) { break; } else { verticalWordPoints += this.ScoreOneTile(play.GetCoordinateX(0), minY - count); ++count; } } // Go down. count = 1; while (true) { if (maxY + count > 14 || this.boardGrid[play.GetCoordinateX(0), maxY + count].IsEmpty()) { break; } else { verticalWordPoints += this.ScoreOneTile(play.GetCoordinateY(0), maxY + count); ++count; } } // Check for gaps between letters in the play, and score them. List<int> coordsY = new List<int>(); for (int i = 0; i < play.GetParallelListLength(); ++i) { coordsY.Add(play.GetCoordinateY(i)); } coordsY.Sort(); count = 1; for (int i = 0; i < coordsY.Count - 1; ++i) { while (coordsY[i] + count < coordsY[i + 1]) { verticalWordPoints += this.ScoreOneTile(play.GetCoordinateX(0), coordsY[i] + count); ++count; } count = 1; } verticalWordPoints *= verticalWordMultiplier; totalPoints += verticalWordPoints; } if (shouldRemoveMultipliers) { // Clear the word and letter multipliers of the GameBoardSquares in the play. for (int i = 0; i < play.GetParallelListLength(); ++i) { this.boardGrid[play.GetCoordinateX(i), play.GetCoordinateY(i)].RemoveScoreMultipliers(); } } // Give the 50 point bonus for using 7 LetterTiles. if (play.GetParallelListLength() == 7) { totalPoints += 50; } return totalPoints; }
/// <summary> /// Lanza el evento de reproducción de una lista /// </summary> private void RaiseEventPlay(MediaAlbumModel reproductionList) { Play?.Invoke(this, new EventArguments.ReproductionListEventArguments(reproductionList)); }
public OCounter(Play.Player player) { counters = player.Counters; }
public void Initialize(Play play) { PlayModel.Play = play; }
public override TimedPlay TimedPlayOnRoll(GameState gamestate, Play play) { throw new NotImplementedException(); }
public Play CalculatePlay(Dictionary <int, double> rankedBoardOptions, Player player, bool deckHasCards) { Play playDecision = new Play(); // If Player has no cards, short curcit and automatically draw if (player.Hand?.Count == 0 || rankedBoardOptions == null || !rankedBoardOptions.Any()) { playDecision.Draw = true; return(playDecision); } if (rankedBoardOptions == null || !rankedBoardOptions.Any()) { throw new ApplicationException("No possible plays to choose from!"); } // Calculate Draw value int missingCards = Configuration._HandSize - player.Hand.Count; double drawValue = Math.Pow(Chromosome.DrawMultiplyer, missingCards); // Re-Weigh board options based on difference between board location and required card value to play var sortedHand = player.Hand.OrderByDescending(x => x); Dictionary <int, double> weightedPlayOptions = new Dictionary <int, double>(); foreach (var play in rankedBoardOptions) { foreach (var card in sortedHand) { if (card <= play.Key) { // First modify value based on Card value multiplyer // Adding _LargeCardPreference here to make larger cards even more desireable to spend double cardValuePercentWeight = (card + Configuration._LargeCardPreference) * Chromosome.CardValueMultiplyer; // Determine the card difference value multiplyer int difference = play.Key - card; double cardDifferencePercentWeight = 1 - (difference * Chromosome.CardLocationDifferenceMultiplyer); // Implement modifiers weightedPlayOptions.Add(play.Key, play.Value * cardValuePercentWeight * cardDifferencePercentWeight); break; } } } // Determine Play var topPlayOption = weightedPlayOptions.OrderByDescending(x => x.Value).FirstOrDefault(); if (topPlayOption.Value >= drawValue || player.Hand.Count == Configuration._HandSize || !deckHasCards) { playDecision.Draw = false; playDecision.PlayedLocationNumber = topPlayOption.Key; foreach (var card in sortedHand) { if (card <= topPlayOption.Key) { playDecision.CardNumber = card; break; } } } else { playDecision.Draw = true; } return(playDecision); }
/// <summary> /// /// </summary> /// <param name="player"></param> /// <param name="play">The play in which moves are in the order they were applied to the board and not reversed.</param> public void UndoPlay(int player, Play play) { for (int i = play.Count - 1; i >= 0; i--) UndoMove(player, play[i]); }
private void StartPlay() { Control.CheckForIllegalCrossThreadCalls = false; VideoLayerCollection message; while ((message = (VideoLayerCollection)treeList1.FocusedNode.GetValue("Message")) == null) { latestParentNodeId = treeList1.FocusedNode.Id; treeList1.MoveNext(); } if (myPlay == null) { SetPlayBar(0, (int)message.PlayLength); this.lblCurName.Text = message.Name; this.lblTotalTime.Text = CommonHelper.FormatTimeToMinute(message.PlayLength); videoSize = message.VideoSize; pnlPlay.Size = videoSize; myPlay = new Play(message, new DESVideoCallBack((int)(curLength / DESConsts.UNITS), this.PlayBar, this.lblCurTime), this.pnlPlay); myPlay.PlayCompleted += new EventHandler(PlayCompleted); myPlay.Run(); this.lblButton.Visible = true; this.lblTop.Visible = true; SetPlayPanel(); SetButton(PlayState.Run); if (!videoSize.Equals(this.pnlPlay.Size)) { videoSize = this.pnlPlay.Size; myPlay.ResizeVideoWindow(videoSize); } if (!videoSize.Equals(this.pnlPlay.Size)) { videoSize = this.pnlPlay.Size; myPlay.ResizeVideoWindow(videoSize); } } ////int msgCount = messages.Length; //Control.CheckForIllegalCrossThreadCalls = false; ////curNum = this.treeList1.get //curNum = this.gridList.SelectedRows.Count > 0 ? this.gridList.SelectedRows[0].Index : 0; //curLength = 0; //if (messages[curNum].PlayLength <= 0) //{ // curNum++; // if (curNum >= this.gridList.Rows.Count) // return; // this.gridList.Rows[curNum].Selected = true; // StartPlay(); //} //if (myPlay == null) //{ // SetPlayBar(0, (int)messages[curNum].PlayLength); // this.gridList.Rows[curNum].Selected = true; // this.lblCurName.Text = this.gridList.SelectedRows[0].Cells["Name"].Value.ToString(); // this.lblTotalTime.Text = this.gridList.SelectedRows[0].Cells["length"].Value.ToString(); // videoSize = messages[curNum].VideoSize; // pnlPlay.Size = videoSize; // myPlay = new Play(messages[curNum], new DESVideoCallBack((int)(curLength / DESConsts.UNITS), this.PlayBar, this.lblCurTime), this.pnlPlay); // myPlay.PlayCompleted += new EventHandler(PlayCompleted); // myPlay.Run(); // this.lblButton.Visible = true; // this.lblTop.Visible = true; // PlayLength = Common.CommonHelper.FormatTime(messages[curNum].PlayLength); // SetPlayPanel(); // SetButton(PlayState.Run); // if (!videoSize.Equals(this.pnlPlay.Size)) // { // videoSize = this.pnlPlay.Size; // myPlay.ResizeVideoWindow(videoSize); // } // if (msgCount > 1 && curNum == 0) // { // btnPrevious.Enabled = false; // btnNext.Enabled = true; // } // else if (msgCount > 1 && curNum == msgCount - 1) // { // btnPrevious.Enabled = true; // btnNext.Enabled = false; // } // else if (msgCount > 1) // { // btnPrevious.Enabled = true; // btnNext.Enabled = true; // } //} #region grid old code //int msgCount = messages.Length; //Control.CheckForIllegalCrossThreadCalls = false; //curNum = this.gridList.SelectedRows.Count > 0 ? this.gridList.SelectedRows[0].Index : 0; //curLength = 0; //if (messages[curNum].PlayLength <= 0) //{ // curNum++; // if (curNum >= this.gridList.Rows.Count) // return; // this.gridList.Rows[curNum].Selected = true; // StartPlay(); //} //if (myPlay == null) //{ // SetPlayBar(0, (int)messages[curNum].PlayLength); // this.gridList.Rows[curNum].Selected = true; // this.lblCurName.Text = this.gridList.SelectedRows[0].Cells["Name"].Value.ToString(); // this.lblTotalTime.Text = this.gridList.SelectedRows[0].Cells["length"].Value.ToString(); // videoSize = messages[curNum].VideoSize; // pnlPlay.Size = videoSize; // myPlay = new Play(messages[curNum], new DESVideoCallBack((int)(curLength / DESConsts.UNITS), this.PlayBar, this.lblCurTime), this.pnlPlay); // myPlay.PlayCompleted += new EventHandler(PlayCompleted); // myPlay.Run(); // this.lblButton.Visible = true; // this.lblTop.Visible = true; // PlayLength = Common.CommonHelper.FormatTime(messages[curNum].PlayLength); // SetPlayPanel(); // SetButton(PlayState.Run); // if (!videoSize.Equals(this.pnlPlay.Size)) // { // videoSize = this.pnlPlay.Size; // myPlay.ResizeVideoWindow(videoSize); // } // if (msgCount > 1 && curNum == 0) // { // btnPrevious.Enabled = false; // btnNext.Enabled = true; // } // else if (msgCount > 1 && curNum == msgCount - 1) // { // btnPrevious.Enabled = true; // btnNext.Enabled = false; // } // else if (msgCount > 1) // { // btnPrevious.Enabled = true; // btnNext.Enabled = true; // } //} #endregion }
public void MakePlay(int player, Play play) { foreach (Move move in play) MakeMove(player, move); }
void DeserializeJson(string str) { Code code = JsonUtility.FromJson <Code>(str); switch (code.code) { case 1: //start { if (wait.activeSelf) { wait.SetActive(false); } int cnt = stones.transform.childCount; for (int i = cnt; i > 0; i--) { Destroy(stones.transform.GetChild(i - 1).transform.gameObject); } endPanel.SetActive(false); GameSingleton.Instance.SetReplay(false); Start start = JsonUtility.FromJson <Start>(str); GameSingleton.Instance.SetStoneState(start.state); if (start.state == PosState.Black) { stoneColor.MyTurn(); } else { stoneColor.OtherTurn(); } if (otherUI.activeSelf) //if replay same oppenent { startUI.SetActive(true); StartCoroutine(StartGame(start.state)); } else { otherUI.SetActive(true); StartCoroutine(OppenentIn(start.state)); } Debug.Log("Start!"); break; } case 2: //play Play play = JsonUtility.FromJson <Play>(str); add.InstantiateOtherStone(play.m, play.n); GameSingleton.Instance.ChangeMyTurn(); stoneColor.MyTurn(); break; case 3: //end End end = JsonUtility.FromJson <End>(str); if (end.winner == GameSingleton.Instance.GetStoneState()) { //끝! endText.GetComponent <Text>().text = "You Win!"; } else { add.InstantiateOtherStone(end.m, end.n); endText.GetComponent <Text>().text = "You Lose"; } endPanel.SetActive(true); break; case 4: //message break; case 6: //exit { int cnt = stones.transform.childCount; for (int i = cnt; i > 0; i--) { Destroy(stones.transform.GetChild(i - 1).transform.gameObject); } exit.SetActive(true); break; } case 7: //give up { Debug.Log("get giveup message"); GameSingleton.Instance.SetGiveUp(true); GiveUp giveUp = JsonUtility.FromJson <GiveUp>(str); if (giveUp.winner == GameSingleton.Instance.GetStoneState()) { //끝! endText.GetComponent <Text>().text = "You Win!"; } else { endText.GetComponent <Text>().text = "You Lose"; } endPanel.SetActive(true); break; } } }
public static bool Play_Unique(Play play) { Play[] results = Play_Search(play.GetPlayName(), play.GetAuthor()); return(results.Length == 1); }
public Play FromSqlDataReader(SqlDataReader reader) { Play obj = new Play(); if (reader["id"] is DBNull == false) { obj.Id = Convert.ToString(reader["id"]); } if (reader["hallId"] is DBNull == false) { obj.HallId = Convert.ToInt16(reader["hallId"]); } if (reader["date"] is DBNull == false) { obj.Date = Convert.ToDateTime(reader["date"]); } if (reader["beginTime"] is DBNull == false) { string str = Convert.ToString(reader["beginTime"]); obj.BeginTime = Convert.ToDateTime(str); } if (reader["movieScheduleId"] is DBNull == false) { obj.MovieScheduleId = Convert.ToString(reader["movieScheduleId"]); } if (reader["hallName"] is DBNull == false) { obj.HallName = Convert.ToString(reader["hallName"]); } if (reader["layoutId"] is DBNull == false) { obj.LayoutId = Convert.ToInt32(reader["layoutId"]); } if (reader["layoutStyle"] is DBNull == false) { obj.LayoutStyle = Convert.ToString(reader["layoutStyle"]); } if (reader["movieId"] is DBNull == false) { obj.MovieId = Convert.ToString(reader["movieId"]); } if (reader["movieName"] is DBNull == false) { obj.MovieName = Convert.ToString(reader["movieName"]); } if (reader["movieDuration"] is DBNull == false) { obj.MovieDuration = Convert.ToByte(reader["movieDuration"]); } if (reader["movieTypeId"] is DBNull == false) { obj.MovieTypeId = Convert.ToByte(reader["movieTypeId"]); } if (reader["movieTypeName"] is DBNull == false) { obj.MovieTypeName = Convert.ToString(reader["movieTypeName"]); } if (reader["scheduleId"] is DBNull == false) { obj.ScheduleId = Convert.ToInt32(reader["scheduleId"]); } if (reader["scheduleName"] is DBNull == false) { obj.ScheduleName = Convert.ToString(reader["scheduleName"]); } if (reader["scheduleBeginDate"] is DBNull == false) { obj.ScheduleBeginDate = Convert.ToDateTime(reader["scheduleBeginDate"]); } if (reader["scheduleDuration"] is DBNull == false) { obj.ScheduleDuration = Convert.ToInt16(reader["scheduleDuration"]); } return(obj); }
private void PlayCompleted(object o, System.EventArgs e) { if (myPlay != null) { myPlay.Dispose(); myPlay = null; } videoSize = Size.Empty; SetButton(PlayState.Stop); this.PlayBar.Value = 0; this.lblCurTime.Text = "00:00"; this.pnlPlay.Refresh(); this.lblButton.Visible = false; this.lblTop.Visible = false; this.Invalidate(); GC.Collect(); GC.WaitForPendingFinalizers(); int oldNodeId = treeList1.FocusedNode.Id; switch (curOper) { case Oper.PrevPlay: case Oper.NextPlay: curOper = Oper.AgainPlay; StartPlay(); break; case Oper.StopPlay: break; default: if (treeList1.MoveNext().Id != oldNodeId) { StartPlay(); } else { treeList1.MoveFirst(); } break; } //LoadList(); //if (curOper == Oper.PrevPlay) //{ // curOper = Oper.AgainPlay; // StartPlay(); //} //else if (curOper == Oper.NextPlay) //{ //} //else if (treeList1.MoveNext().Id != oldNodeId && curOper != Oper.StopPlay) //{ // curOper = Oper.AgainPlay; // StartPlay(); //} //if (curOper == Oper.NextPlay) ////{ //// curNum++; ////} ////else if (curOper == Oper.PrevPlay) ////{ //// curNum--; ////} ////else if (curOper == Oper.StopPlay) ////{ //// curNum = this.gridList.Rows.Count; ////} ////if (curNum >= 0 && curNum < this.gridList.Rows.Count) ////{ //// this.gridList.Rows[curNum].Selected = true; //// curOper = Oper.NextPlay; //// StartPlay(); ////} ////else if (curNum == this.gridList.Rows.Count) ////{ //// curNum = 0; //// this.gridList.Rows[0].Selected = true; ////} #region old code //if (myPlay != null) //{ // myPlay.Dispose(); // myPlay = null; //} //videoSize = Size.Empty; //SetButton(PlayState.Stop); //this.PlayBar.Value = 0; //this.lblCurTime.Text = "00:00"; //this.pnlPlay.Refresh(); //this.lblButton.Visible = false; //this.lblTop.Visible = false; //this.Invalidate(); //GC.Collect(); //GC.WaitForPendingFinalizers(); //if (curOper == Oper.NextPlay) //{ // curNum++; //} //else if (curOper == Oper.PrevPlay) //{ // curNum--; //} //else if (curOper == Oper.StopPlay) //{ // curNum = this.gridList.Rows.Count; //} //if (curNum >= 0 && curNum < this.gridList.Rows.Count) //{ // this.gridList.Rows[curNum].Selected = true; // curOper = Oper.NextPlay; // StartPlay(); //} //else if (curNum == this.gridList.Rows.Count) //{ // curNum = 0; // this.gridList.Rows[0].Selected = true; //} #endregion }
public override TimedPlay TimedPlayOnRoll(GameState gamestate, List<PlayHint> hints, VenueUndoMethod undo_method) { List<Play> legal_plays = gamestate.Board.LegalPlays(gamestate.PlayerOnRoll, gamestate.Dice); List<Move> forced_moves = Board.ForcedMoves(legal_plays); // Sort the moves. foreach (PlayHint hint in hints) { SortMoves(gamestate, hint.Play, legal_plays, forced_moves); } double optimal_move_equity = hints[0].Equity; double doubtful = 0.04; double bad = 0.08; double very_bad = 0.16; /*List<PlayHint> good_hints = new List<PlayHint>(); List<PlayHint> doubtful_hints = new List<PlayHint>(); List<PlayHint> bad_hints = new List<PlayHint>(); List<PlayHint> very_bad_hints = new List<PlayHint>(); // Skip the first one as it is the optimal one. for (int i = 1; i < hints.Count; i++) { double diff = optimal_move_equity - hints[i].Equity; if (diff >= very_bad) very_bad_hints.Add(hints[i]); else if (diff >= bad) very_bad_hints.Add(hints[i]); else if (diff >= doubtful) doubtful_hints.Add(hints[i]); else good_hints.Add(hints[i]); }*/ /*if (legal_plays.Count != hints.Count) { Console.WriteLine("Legal plays and hint plays mis-match"); Console.WriteLine("Legal plays: "); foreach (Play play in legal_plays) Console.WriteLine(play); Console.WriteLine("Hint plays: "); foreach (PlayHint hint in hints) Console.WriteLine(hint); throw new Exception(); }*/ // Is the play an obvious move? Check the equity difference to second best move. bool obvious_move = false; if (legal_plays.Count == 1 || (hints.Count > 1 && (hints[1].Equity - optimal_move_equity) > bad)) obvious_move = true; List<Play> fake_plays = new List<Play>(); if (!obvious_move && undo_method != VenueUndoMethod.None) { // Choose the amount of fake plays. int fake_plays_to_choose = 0; if (random.NextDouble() <= undo_probability) { fake_plays_to_choose++; while (random.NextDouble() < 0.1) fake_plays_to_choose++; } // Choose the fake plays. for (int i = 0; i < fake_plays_to_choose; i++) { int fake_play_index = 1; while (random.Next(3) == 0) { fake_play_index++; if (fake_play_index >= hints.Count) fake_play_index = 0; } // Make it partial? if (random.NextDouble() <= 0.3) { Play partial_play = new Play(); int moves_to_choose = 1; while (random.Next(4) == 0) { moves_to_choose++; if (moves_to_choose >= hints[fake_play_index].Play.Count) moves_to_choose = 1; } for (int m = 0; m < moves_to_choose; m++) { partial_play.Add(hints[fake_play_index].Play[m]); } fake_plays.Add(partial_play); } else fake_plays.Add(hints[fake_play_index].Play); } } TimedPlay timed_play = new TimedPlay(); // Add undo sequences using fake plays. if (!obvious_move && hints.Count > 1 && fake_plays.Count > 0) { List<Move> made_moves = new List<Move>(); //Queue<Move> made_moves = new Queue<Move>(); //Stack<Move> made_moves = new Stack<Move>(); foreach (Play fake_play in fake_plays) { for (int i = 0; i < fake_play.Count; i++) { /*if (made_moves.Count > 0) { int shared = 0; while (shared < made_moves.Count && shared < fake_play.Count && made_moves[shared] == fake_play[shared]) shared++; } else*/ timed_play.Add(new TimedMove(fake_play[i], 0, 0)); //made_moves.Push(fake_play[i]); } // Undo all if (undo_method == VenueUndoMethod.UndoLast) for (int i = 0; i < fake_play.Count; i++) timed_play.Add(TimedMove.CreateUndoMove(0, 0)); else timed_play.Add(TimedMove.CreateUndoMove(0, 0)); } int m = 0; // TODO: Some how check if current move and previous share some similar so not necessary undo all. foreach (Move move in hints[0].Play) timed_play.Add(new TimedMove(move, 0, 0)); } else { // No fake plays, add the optimal move. foreach (Move move in hints[0].Play) timed_play.Add(new TimedMove(move, 0, 0)); } int last_from = -2; bool was_last_undo = false; foreach (TimedMove timed_move in timed_play) { if (timed_move.IsUndo) { if (was_last_undo) { timed_move.WaitBefore = Gaussian.Next(500, 200, 10000, 600, 1.5); timed_move.WaitAfter = random.Next(200); } else { timed_move.WaitBefore = Gaussian.Next(1000, 500, 10000, 2000, 1.5); timed_move.WaitAfter = Gaussian.Next(1000, 50, 10000, 2000, 1.5); } last_from = -2; was_last_undo = true; continue; } was_last_undo = false; if (timed_move.From != last_from) { //timed_move.WaitBefore = Gaussian.Next(500, 250, 2000, 500, 3.0); //timed_move.WaitAfter = random.Next(300); timed_move.WaitBefore = Gaussian.Next(1000, 250, 2000, 1000, 3.0); timed_move.WaitAfter = random.Next(300); } else { //timed_move.WaitBefore = Gaussian.Next(250, 100, 2000, 200, 3.0); //timed_move.WaitAfter = random.Next(100); timed_move.WaitBefore = Gaussian.Next(500, 250, 2000, 200, 3.0); timed_move.WaitAfter = random.Next(250); } // Speedup for pure race or when we have a blockade. if (random.NextDouble() <= 0.9 && (gamestate.Board.IsPureRace() || HasBlockaded(gamestate) || obvious_move)) { timed_move.WaitBefore = (int)(timed_move.WaitBefore * (0.4 + 0.3 * random.NextDouble())); timed_move.WaitAfter = (int)(timed_move.WaitAfter * (0.4 + 0.3 * random.NextDouble())); } last_from = timed_move.From; } // Normalize with coefficient. foreach (TimedMove timed_move in timed_play) { timed_move.WaitBefore = (int)(timed_move.WaitBefore * coefficient); timed_move.WaitAfter = (int)(timed_move.WaitAfter * coefficient); } return timed_play; }
public void WhenIRequestPlayerInformationFromGetPlayInfo() { var play = new Play(loginContext.gameId, loginContext.gameCode, client, loginContext.cookie); user = play.GetPlayerInfo(); }
public void AddPlay(Play play) { playsList.AddPlay(play); UpdateTeamsModels(); }
public void SetSelectedPlay(object play) { selectedPlay = (Play)play; }
public void Initialize() { using (DataContext db = new DataContext(new DbContextOptionsBuilder <DataContext>() .UseSqlServer("Server = (localdb)\\MSSQLLocalDB; Database = Theatre; Trusted_Connection = True; MultipleActiveResultSets = true").Options)) { db.Database.EnsureDeleted(); db.Database.EnsureCreated(); Theatre theatre = new Theatre() { Name = "London theatre", Img = "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Palace_Theatre_-_London.jpg/1200px-Palace_Theatre_-_London.jpg" }; Theatre theatre2 = new Theatre() { Name = "Paris theatre", Img = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/41/Paris_theatre_de_la_Renaissance.jpg/1200px-Paris_theatre_de_la_Renaissance.jpg" }; Play play = new Play() { Name = "Romeo&Julietta", Theatre = theatre, Img = "https://upload.wikimedia.org/wikipedia/commons/thumb/5/55/Romeo_and_juliet_brown.jpg/220px-Romeo_and_juliet_brown.jpg" }; Play play2 = new Play() { Name = "Romeo&Julietta", Theatre = theatre2, Img = "https://upload.wikimedia.org/wikipedia/commons/thumb/5/55/Romeo_and_juliet_brown.jpg/220px-Romeo_and_juliet_brown.jpg" }; Hall hall = new Hall() { Name = "Green Hall", Play = play }; Hall hall2 = new Hall() { Name = "Green Hall", Play = play2 }; List <Place> places = new List <Place>() { new Place() { Buyed = false, Number = 1, Hall = hall }, new Place() { Buyed = false, Number = 2, Hall = hall }, new Place() { Buyed = false, Number = 3, Hall = hall }, new Place() { Buyed = false, Number = 4, Hall = hall }, new Place() { Buyed = false, Number = 5, Hall = hall }, new Place() { Buyed = false, Number = 6, Hall = hall }, new Place() { Buyed = false, Number = 7, Hall = hall }, new Place() { Buyed = false, Number = 8, Hall = hall }, new Place() { Buyed = false, Number = 9, Hall = hall }, new Place() { Buyed = false, Number = 10, Hall = hall }, new Place() { Buyed = false, Number = 11, Hall = hall }, new Place() { Buyed = false, Number = 12, Hall = hall }, }; List <Place> places2 = new List <Place>() { new Place() { Buyed = false, Number = 1, Hall = hall2 }, new Place() { Buyed = false, Number = 2, Hall = hall2 }, new Place() { Buyed = false, Number = 3, Hall = hall2 }, new Place() { Buyed = false, Number = 4, Hall = hall2 }, new Place() { Buyed = false, Number = 5, Hall = hall2 }, new Place() { Buyed = false, Number = 6, Hall = hall2 }, new Place() { Buyed = false, Number = 7, Hall = hall2 }, new Place() { Buyed = false, Number = 8, Hall = hall2 }, new Place() { Buyed = false, Number = 9, Hall = hall2 }, new Place() { Buyed = false, Number = 10, Hall = hall2 }, new Place() { Buyed = false, Number = 11, Hall = hall2 }, new Place() { Buyed = false, Number = 12, Hall = hall2 }, }; db.Theatres.Add(theatre); db.Theatres.Add(theatre2); db.Halls.Add(hall); db.Halls.Add(hall2); db.Plays.Add(play); db.Plays.Add(play2); db.Places.AddRange(places); db.Places.AddRange(places2); db.SaveChanges(); } }
public void UpdateSelectedPlay(Play play) { timeline.SelectedTimeNode = play; notes.Visible = true; notes.Play = play; }
private void animationButton() { Play.BeginAnimation(Button.WidthProperty, animation); Next.BeginAnimation(Button.WidthProperty, animation); Prev.BeginAnimation(Button.WidthProperty, animation); }
/// <summary> /// Tells whether a <see cref="Play"/> can legally be placed onto the board. /// </summary> /// <param name="play">The <see cref="Play"/> being checked.</param> /// <returns>True if play can be added to the board. Returns false otherwise.</returns> public bool PlayIsValid(Play play) { if (play.GetParallelListLength() == 0) { // Cuz that's kinda pointless. return false; } if (play.GetParallelListLength() > 7) { // Yeah . . . no. return false; } if (play.GetParallelListLength() == 1 && this.boardGrid[7, 7].IsEmpty()) { // The first play has to have at least 2 letters in it. return false; } // Make sure the first play puts a LetterTile into the central square. if (this.boardGrid[7, 7].IsEmpty()) { bool putsTileInCentralSquare = false; for (int i = 0; i < play.GetParallelListLength(); ++i) { if (play.GetCoordinateX(i) == 7 && play.GetCoordinateY(i) == 7) { putsTileInCentralSquare = true; } } if (!putsTileInCentralSquare) { return false; } } bool allXCoordinatesAreTheSame = true; bool allYCoordinatesAreTheSame = true; int coordX = play.GetCoordinateX(0); int coordY = play.GetCoordinateY(0); // Make sure that all LetterTiles are in either the same row or in the same column. for (int i = 0; i < play.GetParallelListLength(); ++i) { if (coordX != play.GetCoordinateX(i)) { allXCoordinatesAreTheSame = false; } if (coordY != play.GetCoordinateY(i)) { allYCoordinatesAreTheSame = false; } } // Make sure that there are no duplicates in the play. if (allXCoordinatesAreTheSame) { for (int i = 0; i < play.GetParallelListLength(); ++i) { int numberOfMatches = 0; for (int j = 0; j < play.GetParallelListLength(); ++j) { if (play.GetCoordinateY(i) == play.GetCoordinateY(j)) { ++numberOfMatches; } } if (numberOfMatches != 1) { return false; } else { numberOfMatches = 0; } } } else { for (int i = 0; i < play.GetParallelListLength(); ++i) { int numberOfMatches = 0; for (int j = 0; j < play.GetParallelListLength(); ++j) { if (play.GetCoordinateX(i) == play.GetCoordinateX(j)) { ++numberOfMatches; } } if (numberOfMatches != 1) { return false; } else { numberOfMatches = 0; } } } if (!((allXCoordinatesAreTheSame ^ allYCoordinatesAreTheSame) || play.GetParallelListLength() == 1)) { return false; } // Make sure that no letters are being inserted into where there are already letters. if (allXCoordinatesAreTheSame) { for (int i = 0; i < play.GetParallelListLength(); ++i) { if (!this.boardGrid[coordX, play.GetCoordinateY(i)].IsEmpty()) { return false; } } } if (allYCoordinatesAreTheSame) { for (int i = 0; i < play.GetParallelListLength(); ++i) { if (!this.boardGrid[play.GetCoordinateX(i), coordY].IsEmpty()) { return false; } } } // Make sure that any gaps between the letters in the play are filled by letters that are already on the board. if (allXCoordinatesAreTheSame) { List<int> coordsY = new List<int>(); for (int i = 0; i < play.GetParallelListLength(); ++i) { coordsY.Add(play.GetCoordinateY(i)); } coordsY.Sort(); int prevY = coordsY[0]; for (int i = 1; i < play.GetParallelListLength(); ++i) { while (coordsY[i] != prevY + 1) { if (this.boardGrid[coordX, prevY + 1].IsEmpty()) { return false; } ++prevY; } ++prevY; } } if (allYCoordinatesAreTheSame) { List<int> coordsX = new List<int>(); for (int i = 0; i < play.GetParallelListLength(); ++i) { coordsX.Add(play.GetCoordinateX(i)); } coordsX.Sort(); int prevX = coordsX[0]; for (int i = 1; i < play.GetParallelListLength(); ++i) { while (coordsX[i] != prevX + 1) { if (this.boardGrid[prevX + 1, coordY].IsEmpty()) { return false; } ++prevX; } ++prevX; } } // Make sure that at least one of the letters in the play is adjacent to a letter on the board, // if a play has been added to the board. if (!this.boardGrid[7, 7].IsEmpty()) { bool playIsAdjacentToSomething = false; for (int i = 0; i < play.GetParallelListLength(); ++i) { int x = play.GetCoordinateX(i); int y = play.GetCoordinateY(i); // Check down. if (y < 14 && !this.boardGrid[x, y + 1].IsEmpty()) { playIsAdjacentToSomething = true; break; } // Check up. if (y > 0 && !this.boardGrid[x, y - 1].IsEmpty()) { playIsAdjacentToSomething = true; break; } // Check left. if (x > 0 && !this.boardGrid[x - 1, y].IsEmpty()) { playIsAdjacentToSomething = true; break; } // Check right. if (x < 14 && !this.boardGrid[x + 1, y].IsEmpty()) { playIsAdjacentToSomething = true; break; } } return playIsAdjacentToSomething; } return true; }
public static void Main(string[] args) { RunMenu(); Play.PlayGame(new GameInstance()); }
public override void OnAuthenticated() { Play.Log("OnAuthenticated", flag); Play.CreateRoom(); flag++; }
public PlayHint() { //moves = new List<Move>(); play = new Play(); equity = double.NaN; }
public override TimedPlay TimedPlayOnRoll(GameState gamestate, Play play) { //Console.WriteLine("Sorting moves..."); List<Play> legal_plays = gamestate.Board.LegalPlays(gamestate.PlayerOnRoll, gamestate.Dice); List<Move> forced_moves = Board.ForcedMoves(legal_plays); //Console.Write("Forced moves: "); //foreach (Move move in forced_moves) // Console.Write(move + " "); //Console.WriteLine(); if (gamestate.Dice[0] != gamestate.Dice[1]) { // Both are on the bar, sort the enter which uses bigger die as first. if (play.Count == 2 && play[0].IsEnter && play[1].IsEnter && play[1].To < play[0].To) play.Reverse(); // Third condition avoids sequences where the second move is dependant on the first one if (play.Count == 2 && /*remove me when fixed*/ !play[0].IsEnter && !play[1].IsEnter && forced_moves.Count == 0 && gamestate.Board.PointCount(gamestate.PlayerOnRoll, play[1].From) > 0) { // Case where there are two moves and they share the same 'from' point, sort so that the one with bigger distance is first. if (play[0].From == play[1].From && play[0].Distance < play[1].Distance) play.Reverse(); // Chain move, instead of 3/1 6/3 make 6/3/1 else if (play[0].From == play[1].To) play.Reverse(); // If only one is a hit, greedily sort it as the first move else if (play[1].HasHits && !play[0].HasHits) play.Reverse(); else if (!play[0].HasHits && play[1].HasHits) play.Reverse(); else { } } } else { /*if (play.Count == 4) { }*/ } TimedPlay timed_play = new TimedPlay(); if (gamestate.Board.IsPureRace()) { foreach (Move move in play) { timed_play.Add(new TimedMove(move, random.Next(100, 500), random.Next(200))); } } else { foreach (Move move in play) { timed_play.Add(new TimedMove(move, random.Next(250, 500), random.Next(250))); } } return timed_play; }
public PlayHint(IEnumerable<Move> moves, double equity) { play = new Play(moves); this.equity = equity; }
private void dataPlayersToolStripMenuItem_Click(object sender, EventArgs e) { if(this.HomeClub.ClubId != 0 && this.GuestClub.ClubId != 0) { FrmAddPlayers dataAddPlayers = new FrmAddPlayers(this.HomeClub.ClubId, this.GuestClub.ClubId, this.HomePlayers, this.GuestPlayers); dataAddPlayers.ShowDialog(); if (dataAddPlayers.PlayersAddSuccess) { Thread loadingThread = new Thread(new ThreadStart(showLoadingForm)); loadingThread.Start(); this.HomePlays = new BindingList<Play>(); this.GuestPlays = new BindingList<Play>(); this.HomePlayers = dataAddPlayers.HomePlayersPlay; this.GuestPlayers = dataAddPlayers.GuestPlayersPlay; this.HomeTeamPlayers.Clear(); this.GuestTeamPlayers.Clear(); using (var db = new MatchReporterEntities()) { List<Play> previousPlays = new List<Play>(db.Play.Where<Play>(p => p.MatchId == this.Match.MatchId).ToList<Play>()); foreach(Play play in previousPlays) { db.Play.Remove(play); } db.SaveChanges(); } foreach (Player player in this.HomePlayers) { TeamPlayer teamPlayer = new TeamPlayer(player.PlayerId, player.FirstName, player.LastName, player.Number); this.HomeTeamPlayers.Add(teamPlayer); Play play = new Play(this.Match.MatchId, player.PlayerId); this.HomePlays.Add(play); } foreach (Player player in this.GuestPlayers) { TeamPlayer teamPlayer = new TeamPlayer(player.PlayerId, player.FirstName, player.LastName, player.Number); this.GuestTeamPlayers.Add(teamPlayer); Play play = new Play(this.Match.MatchId, player.PlayerId); this.GuestPlays.Add(play); } using (var db = new MatchReporterEntities()) { foreach(Play play in this.HomePlays) { db.Play.Add(play); } foreach(Play play in this.GuestPlays) { db.Play.Add(play); } db.SaveChanges(); this.SavedPlays = true; } dgvHomeTeam.DataSource = this.HomeTeamPlayers; dgvGuestTeam.DataSource = this.GuestTeamPlayers; dgvHomeTeam.Refresh(); dgvGuestTeam.Refresh(); btnHomeGoal.Enabled = true; btnGuestGoal.Enabled = true; btnHome7m.Enabled = true; btnGuest7m.Enabled = true; btnHomeWarning.Enabled = true; btnGuestWarning.Enabled = true; btnHomeSuspension.Enabled = true; btnGuestSuspension.Enabled = true; btnHomeDisqualification.Enabled = true; btnGuestDisqualification.Enabled = true; btnHomeDisqualificationReport.Enabled = true; btnGuestDisqualificationReport.Enabled = true; btnHomeUndo.Enabled = true; btnGuestUndo.Enabled = true; loadingThread.Abort(); } //dataAddPlayers.Dispose(); } else { MessageBox.Show(this, "Da biste dodali igrače, prvo je potrebno dodati momčadi.", "Greška", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void GetPlayList() { string strText = ""; Regex regex = null; MatchCollection matchCollection = null; if (radioButton1.Checked) //优酷 { strText = GetStr(getcode(textBox1.Text, "utf-8"), "p pv", "上一页"); regex = new Regex(@"_link""><a href=""(?<word>.*?)"" title=""(?<title>.*?)"" target"); matchCollection = regex.Matches(strText); } else { strText = GetStr(getcode(textBox1.Text, "gb2312"), "body", "//body"); regex = new Regex(@"_blank"" href=""(?<word>.*?)"" title='(?<title>.*?)'>"); matchCollection = regex.Matches(strText); if (matchCollection.Count==0) { regex = new Regex(@"class=""plus""></a> <span> <a href=""(?<word>.*?)"" title=""(?<title>.*?)"" target"); matchCollection = regex.Matches(strText); } if (matchCollection.Count==0) { regex = new Regex(@"box_text""><a href=""//(?<word>.*?)"" target=""show_v"" title=""(?<title>.*?)"">"); matchCollection = regex.Matches(strText); } } foreach (Match m in matchCollection) { Play p = new Play { _title = m.Groups["title"].Value, url = m.Groups["word"].Value, IsAdd = false }; try { PlayList.Add(p._title, p); } catch (Exception) { break; } strList.Add(m.Groups["word"].Value); } richTextBox1.Text += "解析完成\r\n"; Bind(); //DialogResult dr = MessageBox.Show("视频解析完成,是否继续添加?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); //if (dr == DialogResult.Cancel) //{ // button1.Enabled = true; //} MessageBox.Show("解析完成!"); button1.Enabled = true; }
public override void OnJoinRoomFailed(int errorCode, string reason) { Play.Log("OnJoinRoomFailed: " + reason); }
public void CatchPlayActivity(Play p) { p.Catched = true; p.StateString = judge.CurState.ToString(); }
public PlayHint(IEnumerable<Move> moves) { //this.moves = moves; play = new Play(moves); equity = double.NaN; }
public Experiment(string name, Play play = Play.Deactivated) { this.Name = name; this.Play = play; }
/// <summary> /// /// </summary> /// <param name="gamestate"></param> /// <param name="play">The actual play we want to time and input.</param> /// <returns></returns> public abstract TimedPlay TimedPlayOnRoll(GameState gamestate, Play play);
//todo: exception if not possible? public async Task AddPlay(Play play) { await _playRepo.AddPlay(play); }