public static ProcessResultArray <Clip> ProcessCommand(Command command, Clip[] incomingClips, ClipMetaData targetMetadata) { var clips = new Clip[incomingClips.Length]; for (var i = 0; i < incomingClips.Length; i++) { clips[i] = new Clip(incomingClips[i]); } ProcessResultArray <Clip> resultContainer; switch (command.Id) { case TokenType.Arpeggiate: resultContainer = Arpeggiate.Apply(command, clips); break; case TokenType.Concat: resultContainer = Concat.Apply(clips); break; case TokenType.Crop: resultContainer = Crop.Apply(command, clips); break; case TokenType.Filter: resultContainer = Filter.Apply(command, clips); break; case TokenType.Interleave: resultContainer = Interleave.Apply(command, targetMetadata, clips); break; case TokenType.InterleaveEvent: var(success, msg) = OptionParser.TryParseOptions(command, out InterleaveOptions options); if (!success) { return(new ProcessResultArray <Clip>(msg)); } options.Mode = InterleaveMode.Event; resultContainer = Interleave.Apply(options, targetMetadata, clips); break; case TokenType.Legato: resultContainer = Legato.Apply(clips); break; case TokenType.Mask: resultContainer = Mask.Apply(command, clips); break; case TokenType.Monophonize: resultContainer = Monophonize.Apply(clips); break; case TokenType.Quantize: resultContainer = Quantize.Apply(command, clips); break; case TokenType.Ratchet: resultContainer = Ratchet.Apply(command, clips); break; case TokenType.Relength: resultContainer = Relength.Apply(command, clips); break; case TokenType.Resize: resultContainer = Resize.Apply(command, clips); break; case TokenType.Scale: resultContainer = Scale.Apply(command, clips); break; case TokenType.Scan: resultContainer = Scan.Apply(command, clips); break; case TokenType.SetLength: resultContainer = SetLength.Apply(command, clips); break; case TokenType.SetRhythm: resultContainer = SetRhythm.Apply(command, clips); break; case TokenType.Shuffle: resultContainer = Shuffle.Apply(command, clips); break; case TokenType.Skip: resultContainer = Skip.Apply(command, clips); break; case TokenType.Slice: resultContainer = Slice.Apply(command, clips); break; case TokenType.Take: resultContainer = Take.Apply(command, clips); break; case TokenType.Transpose: resultContainer = Transpose.Apply(command, clips); break; default: return(new ProcessResultArray <Clip>($"Unsupported command {command.Id}")); } return(resultContainer); }
/// <summary> /// Generates a 'standard' galaxy, X rings around Mecatol w/ home systems on outside edge. /// </summary> /// <param name="rad">'radius' of the galaxy to be generated. For this shape, also equals the number of rings around Mecatol</param> /// <param name="players">Number of players in current game</param> /// <param name="shuffle">The 'Shuffle' object used for randomization. Passing one in makes it less likely that seeding weirdness produces identical galaxies</param> public void GenerateStandard(int rad, int players = 6, Shuffle shuffle = null) { // TODO: Set HSLocations for player counts other than 6 // TODO: Maybe pull this out as a helper function? HSLocations = new List <Tuple <int, int> >(); if (players == 6) { HSLocations.Add(new Tuple <int, int>(0, rad)); HSLocations.Add(new Tuple <int, int>(0, 2 * rad)); HSLocations.Add(new Tuple <int, int>(rad, 0)); HSLocations.Add(new Tuple <int, int>(rad, 2 * rad)); HSLocations.Add(new Tuple <int, int>(2 * rad, 0)); HSLocations.Add(new Tuple <int, int>(2 * rad, rad)); } // Set player# of HS tiles (used for staking claims & making sure not to put an actual tile in that spot) for (int i = 1; i <= players; i++) { Tuple <int, int> tuple = HSLocations[i - 1]; tiles[tuple.Item1][tuple.Item2].playerNum = i; } int placeableTileCount = 3 * rad * (rad + 1) - players; // TODO: Consider making tileset configurable. For now, just keep adding a full set of game tiles until the required amount is reached. // May require multiple game copies, and/or the expansion. List <SystemTile> tileset = new List <SystemTile>(); while (tileset.Count < placeableTileCount) { tileset.AddRange(TilesetGenerator.GetAllTiles()); } shuffle = shuffle ?? new Shuffle(); shuffle.ShuffleList <SystemTile>(tileset); tileset = tileset.GetRange(0, placeableTileCount); int width = 2 * rad + 1; int index = 0; for (int x = 0; x < width; x++) { for (int y = 0; y < width; y++) { if (x + y >= rad && x + y <= 3 * rad && !(x == rad && y == rad)) { if (tiles[x][y].playerNum == 0) { // for tiles within shape of galaxy that are not Home Systems, assign a tile. tiles[x][y] = tileset[index]; index++; } } else if (x == rad && y == rad) { // "He who controls the Mecatol controls the universe" tiles[x][y] = TilesetGenerator.GetMecatol(); } else { // tiles outside of the galaxy are assigned player number -1 tiles[x][y].playerNum = -1; } } } // make sure that all tiles adjacent to tile 'A' are within 'A's adjacent list for (int x = 0; x < width; x++) { for (int y = 0; y < width; y++) { if (tiles[x][y].playerNum >= 0) { if (x < 2 * rad && tiles[x + 1][y].playerNum >= 0) { tiles[x][y].adjacent.Add(tiles[x + 1][y]); tiles[x + 1][y].adjacent.Add(tiles[x][y]); } if (y < 2 * rad && tiles[x][y + 1].playerNum >= 0) { tiles[x][y].adjacent.Add(tiles[x][y + 1]); tiles[x][y + 1].adjacent.Add(tiles[x][y]); } if (x < 2 * rad && y > 0 && tiles[x + 1][y - 1].playerNum >= 0) { tiles[x][y].adjacent.Add(tiles[x + 1][y - 1]); tiles[x + 1][y - 1].adjacent.Add(tiles[x][y]); } } } } connectWormholes(); }
public override Node select() { selected = children[Shuffle.rouletteSelect(this.dp)]; return(this); }
public History fit(Array x = null, Array y = null, int batch_size = 32, int epochs = 1, int verbose = 1, CallbackList callbacks = null, double validation_split = 0, IList <Array> validation_data = null, Shuffle shuffle = Shuffle.True, Dictionary <int, double> class_weight = null, Array sample_weight = null, int initial_epoch = 0, object kwargs = null, int?nb_epoch = null) { // Legacy support if (nb_epoch != null) { Trace.TraceWarning("The 'nb_epoch' argument in 'fit' has been renamed 'epochs'."); epochs = nb_epoch.Value; } return(this.fit( x.dict_from_single(), y.dict_from_single(), batch_size, epochs, verbose, callbacks, validation_split, validation_data?.Select(a => a.dict_from_single()).ToList(), shuffle, class_weight?.Select(p => (p.Key.ToString(), p.Value)).ToDictionary(a => a.Item1, b => b.Item2).dict_from_single(), sample_weight.dict_from_single(), initial_epoch, kwargs)); }
public WindowViewModel() { Title = "ShuffleLunch"; _lunchInfo = new LunchInfo(); var setting = Setting.Instance; setting.Get(); FontSizeDesk = setting.FontSizeDesk; FontSizePerson = setting.FontSizePerson; ImageWidth = setting.ImageWidth; ImageHeight = setting.ImageHeight; ShuffleImageWidth = setting.ShuffleImageWidth; ShuffleImageHeight = setting.ShuffleImageHeight; FileOpen = new DelegateCommand(_ => { var b = _lunchInfo.Get(); if (b == false) { return; } PersonList = new ObservableCollection <Person>(_lunchInfo.PersonList()); DeskList = new ObservableCollection <Desk>(_lunchInfo.DeskList()); PersonAndDeskList = new ObservableCollection <PersonAndDesk>(_lunchInfo.PersonAndDeskList()); }); ButtonShuffle = new DelegateCommand(_ => { var shuffle = new Shuffle(); var b = shuffle.shuffle(DeskList.ToList <Desk>(), PersonAndDeskList.ToList <PersonAndDesk>()); if (b == false) { return; } ShuffleResultList = new ObservableCollection <ShuffleResult>(shuffle.Get()); }); ButtonAddUser = new DelegateCommand(_ => { var deskList = new List <string>(); for (int i = 0; i < DeskList.Count; i++) { deskList.Add(DeskList[i].name); } var myAssembly = Assembly.GetEntryAssembly(); string path = myAssembly.Location; path = path.Replace("ShuffleLunch.exe", ""); var personAndDesk = new PersonAndDesk { name = AddUserName, desk = deskList, selectDesk = 0, image = path + @"image\guest.png" }; PersonAndDeskList.Add(personAndDesk); AddUserName = ""; }); ExportImage = new DelegateCommand(element => { PngExporter.Export((FrameworkElement)element); }); }
public void GenerateGrid() { allTileCoords = new List <Coord>(); for (int x = 0; x < mapSize.x; x++) { for (int y = 0; y < mapSize.y; y++) { allTileCoords.Add(new Coord(x, y)); } } shuffledTileCoords = new Queue <Coord>(Shuffle.ShuffleArray(allTileCoords.ToArray(), seed)); mapCentre = new Coord((int)mapSize.x / 2, (int)mapSize.y / 2); string holderName = "Generated Grid"; if (transform.Find(holderName)) { DestroyImmediate(transform.Find(holderName).gameObject); } Transform gridHolder = new GameObject(holderName).transform; gridHolder.parent = transform; for (int x = 0; x < mapSize.x; x++) { for (int y = 0; y < mapSize.y; y++) { Coord tilePos = new Coord(x, y); Vector3 tilePosition = CoordToPosition(tilePos); Transform newTile = Instantiate(tilePrefab, tilePosition, Quaternion.Euler(Vector3.right * 90)) as Transform; newTile.localScale = Vector3.one * (1 - outlinePercent); newTile.parent = gridHolder; } } obstacleMap = new bool[(int)mapSize.x, (int)mapSize.y]; int obstacleCount = (int)(mapSize.x * mapSize.y * obstaclePercent); int currentObstacleCount = 0; for (int i = 0; i < obstacleCount; i++) { Coord randomCoord = GetRandomCoord(); obstacleMap[randomCoord.x, randomCoord.y] = true; currentObstacleCount++; if (randomCoord != mapCentre && MapFullyAccesible(obstacleMap, currentObstacleCount) && randomCoord != playerSpawnPosition) { Transform newObstacle = Instantiate(obstaclePrefab, CoordToPosition(randomCoord), Quaternion.identity) as Transform; newObstacle.localScale = Vector3.one * (1 - outlinePercent); newObstacle.position = newObstacle.position + new Vector3(0, newObstacle.localScale.y / 2, 0); newObstacle.parent = gridHolder; } else { obstacleMap[randomCoord.x, randomCoord.y] = false; currentObstacleCount--; } } }
public static void OnSkillShow(Room room, Player player, string skill) { List <Client> ais = new List <Client>(); foreach (Client client in room.Clients) { if (client.UserId < 0) { ais.Add(client); } } if (ais.Count == 0) { return; } DataRow[] rows = Engine.GetSkillShowingLines(); foreach (DataRow row in rows) { if (row["skills"].ToString() == skill) { foreach (Client ai in ais) { //几率1/3聊天 if (Shuffle.random(1, 3)) { //50%随机是发言还是表情 bool speak = Shuffle.random(1, 2); if (room.Setting.SpeakForbidden) { speak = false; } //50%随机 int num = Shuffle.random(1, 2)? 1 : 2; if (room.GetClient(player) == ai) { if (speak) { string message = row[string.Format("self_lines{0}", num)].ToString(); if (!string.IsNullOrEmpty(message)) { room.Speak(ai, message); } } else { string messages = row[string.Format("self_emotion{0}", num)].ToString(); if (!string.IsNullOrEmpty(messages)) { string[] ms = messages.Split('/'); room.Emotion(ai, ms[0], ms[1]); } } } else { if (speak) { string message = row[string.Format("lines{0}", num)].ToString(); if (!string.IsNullOrEmpty(message)) { room.Speak(ai, message); } } else { string messages = row[string.Format("emotion{0}", num)].ToString(); if (!string.IsNullOrEmpty(messages)) { string[] ms = messages.Split('/'); room.Emotion(ai, ms[0], ms[1]); } } } } } } } }
public void ShuffleDiscard() { System.Random rnd = new System.Random(); Shuffle.ShuffleList(cards, rnd); //shuffle discard pile }
//判定结束 private static void OnJudgeDone(Room room, Player player, object data) { if (player.ClientId < 0 && data is JudgeStruct judge) { Client client = room.GetClient(player); if (judge.Reason == Lightning.ClassName) { bool suc = RoomLogic.GetCardSuit(room, judge.Card) == WrappedCard.CardSuit.Spade && RoomLogic.GetCardNumber(room, judge.Card) > 1 && RoomLogic.GetCardNumber(room, judge.Card) < 10; if (suc && Shuffle.random(1, 3)) { bool speak = Shuffle.random(1, 2); if (room.Setting.SpeakForbidden) { speak = false; } DataRow row = Engine.GetLines(client.Profile.NickName); if (speak) { string message = row["lightning_success1"].ToString(); if (!string.IsNullOrEmpty(message)) { room.Speak(client, message); } } else { string messages = row["lightning_success2"].ToString(); if (!string.IsNullOrEmpty(messages)) { string[] ms = messages.Split('/'); room.Emotion(client, ms[0], ms[1]); } } } } else if (judge.Reason == Indulgence.ClassName && Shuffle.random(1, 3)) { bool suc = RoomLogic.GetCardSuit(room, judge.Card) != WrappedCard.CardSuit.Heart; bool speak = Shuffle.random(1, 2); if (room.Setting.SpeakForbidden) { speak = false; } DataRow row = Engine.GetLines(client.Profile.NickName); if (speak) { string message = suc ? row["indu_success1"].ToString() : row["indu_fail1"].ToString(); if (!string.IsNullOrEmpty(message)) { room.Speak(client, message); } } else { string messages = suc ? row["indu_success2"].ToString() : row["indu_fail2"].ToString(); if (!string.IsNullOrEmpty(messages)) { string[] ms = messages.Split('/'); room.Emotion(client, ms[0], ms[1]); } } } } }
//阵亡聊天 private static void OnDeath(Room room, Player player, object data) { if (player.ClientId < 0 && data is DeathStruct death) { //几率1/3聊天 if (Shuffle.random(1, 3)) { Client client = room.GetClient(player); //50%随机是发言还是表情 bool speak = Shuffle.random(1, 2); if (room.Setting.SpeakForbidden) { speak = false; } DataRow row = Engine.GetLines(client.Profile.NickName); if (speak) { string message = row["death1"].ToString(); if (!string.IsNullOrEmpty(message)) { if (message.Contains("%1")) { if (death.Damage.From != null) { message = message.Replace("%1", death.Damage.From.SceenName); } else { message = string.Empty; } } if (!string.IsNullOrEmpty(message)) { room.Speak(client, message); } } } else { string messages = row["death2"].ToString(); if (!string.IsNullOrEmpty(messages)) { string[] ms = messages.Split('/'); room.Emotion(client, ms[0], ms[1]); } } } //杀死非友方时 if (death.Damage.From != null && death.Damage.From != player && death.Damage.From.ClientId < 0 && !RoomLogic.IsFriendWith(room, death.Damage.From, player) && Shuffle.random(1, 3)) { Client client = room.GetClient(death.Damage.From); //50%随机是发言还是表情 bool speak = Shuffle.random(1, 2); if (room.Setting.SpeakForbidden) { speak = false; } DataRow row = Engine.GetLines(client.Profile.NickName); if (speak) { string message = row["kill1"].ToString(); if (!string.IsNullOrEmpty(message) && !message.Contains("%1")) { message = message.Replace("%1", player.SceenName); room.Speak(client, message); } } else { string messages = row["kill2"].ToString(); if (!string.IsNullOrEmpty(messages)) { string[] ms = messages.Split('/'); room.Emotion(client, ms[0], ms[1]); } } } } }
private static void OnUseCard(Room room, Player player, object data) { if (data is CardUseStruct use) { if (use.Card.Name == Analeptic.ClassName && (use.Reason == CardUseStruct.CardUseReason.CARD_USE_REASON_PLAY || room.GetRoomState().GetCurrentCardUsePattern(player) == "@@rende") && use.Card.Skill != "_zhendu") { List <Client> ais = new List <Client>(); foreach (Player p in room.GetAlivePlayers()) { Client client = room.GetClient(p); if (p.ClientId < 0 && !ais.Contains(client) && RoomLogic.InMyAttackRange(room, player, p) && !RoomLogic.IsFriendWith(room, player, p) && room.GetClient(player) != client && Shuffle.random(1, 3)) { ais.Add(client); } } if (ais.Count == 0) { return; } foreach (Client client in ais) { bool speak = Shuffle.random(1, 2); if (room.Setting.SpeakForbidden) { speak = false; } DataRow row = Engine.GetLines(client.Profile.NickName); if (speak) { string message = row["other_drunk1"].ToString(); if (!string.IsNullOrEmpty(message)) { message = message.Replace("%1", player.SceenName); room.Speak(client, message); } } else { string messages = row["other_drunk2"].ToString(); if (!string.IsNullOrEmpty(messages)) { string[] ms = messages.Split('/'); room.Emotion(client, ms[0], ms[1]); } } } } else if (player.ClientId < 0 && use.Card.Name.Contains(Slash.ClassName) && (use.Reason == CardUseStruct.CardUseReason.CARD_USE_REASON_PLAY || room.GetRoomState().GetCurrentCardUsePattern(player) == "@@rende") && use.To.Count == 1 && !RoomLogic.IsFriendWith(room, player, use.To[0]) && Shuffle.random(1, 3)) { Client client = room.GetClient(player); bool speak = Shuffle.random(1, 2); if (room.Setting.SpeakForbidden) { speak = false; } DataRow row = Engine.GetLines(client.Profile.NickName); if (speak) { string message = row["slash_use1"].ToString(); if (!string.IsNullOrEmpty(message)) { message = message.Replace("%1", use.To[0].SceenName); room.Speak(client, message); } } else { string messages = row["slash_use2"].ToString(); if (!string.IsNullOrEmpty(messages)) { string[] ms = messages.Split('/'); room.Emotion(client, ms[0], ms[1]); } } } } }
private static void OnTargeted(Room room, Player player, object data) { if (data is CardUseStruct use) { if (use.Card.Name.Contains(Slash.ClassName) && use.To.Count > 0 && room.Setting.GameMode == "Hegemony") { List <Client> ais = new List <Client>(); foreach (Player p in use.To) { Client client = room.GetClient(p); if (p.ClientId < 0 && !ais.Contains(client) && room.GetClient(p) != client && !room.GetAI(player, true).IsKnown(player, p) && Shuffle.random(1, 3)) { ais.Add(client); } } if (ais.Count == 0) { return; } foreach (Client client in ais) { bool speak = Shuffle.random(1, 2); if (room.Setting.SpeakForbidden) { speak = false; } DataRow row = Engine.GetLines(client.Profile.NickName); if (speak) { string message = row["slash_target1"].ToString(); if (!string.IsNullOrEmpty(message)) { message = message.Replace("%1", player.SceenName); room.Speak(client, message); } } else { string messages = row["slash_target2"].ToString(); if (!string.IsNullOrEmpty(messages)) { string[] ms = messages.Split('/'); room.Emotion(client, ms[0], ms[1]); } } } } } }
//private void Awake() //{ // //sets a random Seed ~ this should be done in the game manager later // if (RandomSeed) // seed = Random.Range(-10000, 10000); // Generate(); //} public void Generate() { //Creates the village gameobject village = new GameObject(); village.name = "Village"; village.transform.position = Vector3.zero; village.isStatic = true; //Sets up for the shuffle for (int i = 0; i < VillageSize.x; i++) { for (int j = 0; j < VillageSize.y; j++) { Tiles.Add(new Coord(i, j)); } } //queues shuffle shuffledCoords = new Queue <Coord>(Shuffle.ShuffleArray(Tiles.ToArray())); //sets up the center of the map to be empty MapCenter = new Coord((int)(VillageSize.x * .5f), (int)(VillageSize.y * .5f)); //sets up the village map buildingMap = new bool[(int)VillageSize.x, (int)VillageSize.y]; //max number of houses allowed int houseCount = (int)(VillageSize.x * VillageSize.y * percentage); int currentHouseCount = 0; //while under the max number of houses for (int i = 0; i < houseCount; i++) { //get the next coord Coord rnd = GetRandomCoord(); buildingMap[rnd.x, rnd.y] = true; currentHouseCount++; //if its the map center of the building isnt accessible anymore and checks its within the radius if (rnd == MapCenter || !IsAccessible(buildingMap, currentHouseCount) || (new Vector2(rnd.x, rnd.y) - new Vector2(MapCenter.x, MapCenter.y)).magnitude > radius) { buildingMap[rnd.x, rnd.y] = false; currentHouseCount--; } } //smooth out the houses into blocks for (int i = 0; i < numOfIterations; i++) { SmoothOutSides(); } //build the connected cells together into blocks for (int x = 0; x < VillageSize.x; x++) { for (int y = 0; y < VillageSize.y; y++) { //local function ~ if its within the list then return true bool inList(Coord c) { for (int i = 0; i < buildings.Count; i++) { if (buildings[i].tiles.Contains(c)) { return(true); } } return(false); } if (buildingMap[x, y] && !inList(new Coord(x, y))) { //create a new object GameObject buildingGroup = new GameObject(); buildingGroup.name = "Building Group"; buildingGroup.transform.parent = village.transform; buildingGroup.isStatic = true; //add the building component to it Building b = buildingGroup.AddComponent <Building>(); //add in the current coord to that list b.AddCoord(new Coord(x, y)); //create a temporary search list List <Coord> toSearch = new List <Coord>(); //add in the close coords if (x + 1 < VillageSize.x) { toSearch.Add(new Coord(x + 1, y)); } if (x - 1 >= 0) { toSearch.Add(new Coord(x - 1, y)); } if (y + 1 < VillageSize.y) { toSearch.Add(new Coord(x, y + 1)); } if (y - 1 >= 0) { toSearch.Add(new Coord(x, y - 1)); } //while there are still coords to search through while (toSearch.Count > 0) { //take the first element in the array Coord searchingCoord = toSearch[0]; //if this is a taken space on the map if (buildingMap[searchingCoord.x, searchingCoord.y]) { //add the coord to the buildings list b.AddCoord(searchingCoord); //searches through all the next coords if (searchingCoord.x + 1 < VillageSize.x) { if (!b.tiles.Contains(new Coord(searchingCoord.x + 1, searchingCoord.y)) && !toSearch.Contains(new Coord(searchingCoord.x + 1, searchingCoord.y))) { toSearch.Add(new Coord(searchingCoord.x + 1, searchingCoord.y)); } } if (searchingCoord.x - 1 >= 0) { if (!b.tiles.Contains(new Coord(searchingCoord.x - 1, searchingCoord.y)) && !toSearch.Contains(new Coord(searchingCoord.x - 1, searchingCoord.y))) { toSearch.Add(new Coord(searchingCoord.x - 1, searchingCoord.y)); } } if (searchingCoord.y + 1 < VillageSize.y) { if (!b.tiles.Contains(new Coord(searchingCoord.x, searchingCoord.y + 1)) && !toSearch.Contains(new Coord(searchingCoord.x, searchingCoord.y + 1))) { toSearch.Add(new Coord(searchingCoord.x, searchingCoord.y + 1)); } } if (searchingCoord.y - 1 >= 0) { if (!b.tiles.Contains(new Coord(searchingCoord.x, searchingCoord.y - 1)) && !toSearch.Contains(new Coord(searchingCoord.x, searchingCoord.y - 1))) { toSearch.Add(new Coord(searchingCoord.x, searchingCoord.y - 1)); } } } //remove it from the search list toSearch.Remove(searchingCoord); } //building validating if (b.Size <= MinBuildingSize || b.Size > MaxBuildingSize) { foreach (Coord c in b.tiles) { buildingMap[c.x, c.y] = false; } DestroyImmediate(buildingGroup); } else { //if its a valid building, make it more blocky for (int j = 0; j < 20; j++) { List <Coord> changed = b.Smooth(); foreach (Coord c in changed) { buildingMap[c.x, c.y] = true; } } //adds the building component to a list buildings.Add(b); } } } } //create paths around buildings. CreatePath(); //sort buildings buildings = BuildingSorter(buildings, true); //assign buildings AssingFunction(); //create buildings CreateBuildings(); SpawnNPC(); }
public override void PrepareForStart(Room room, ref List <Player> room_players, ref List <int> game_cards, ref List <int> m_drawPile) { //生成卡牌 game_cards = Engine.GetGameCards(room.Setting.CardPackage); m_drawPile = game_cards; Shuffle.shuffle(ref m_drawPile); //首先添加4位AI,不需要用到client for (int i = 4; i < 8; i++) { room_players.Add(new Player { Name = string.Format("SGS{0}", i + 1), Seat = i + 1 }); } //根据随机座次 List <List <Game3v3Camp> > camps = new List <List <Game3v3Camp> > { new List <Game3v3Camp> { Game3v3Camp.S_CAMP_COOL, Game3v3Camp.S_CAMP_WARM, Game3v3Camp.S_CAMP_WARM, Game3v3Camp.S_CAMP_COOL, Game3v3Camp.S_CAMP_COOL, Game3v3Camp.S_CAMP_WARM, Game3v3Camp.S_CAMP_WARM, Game3v3Camp.S_CAMP_COOL }, new List <Game3v3Camp> { Game3v3Camp.S_CAMP_COOL, Game3v3Camp.S_CAMP_WARM, Game3v3Camp.S_CAMP_COOL, Game3v3Camp.S_CAMP_COOL, Game3v3Camp.S_CAMP_WARM, Game3v3Camp.S_CAMP_WARM, Game3v3Camp.S_CAMP_COOL, Game3v3Camp.S_CAMP_WARM }, new List <Game3v3Camp> { Game3v3Camp.S_CAMP_COOL, Game3v3Camp.S_CAMP_WARM, Game3v3Camp.S_CAMP_COOL, Game3v3Camp.S_CAMP_WARM, Game3v3Camp.S_CAMP_COOL, Game3v3Camp.S_CAMP_WARM, Game3v3Camp.S_CAMP_COOL, Game3v3Camp.S_CAMP_WARM }, new List <Game3v3Camp> { Game3v3Camp.S_CAMP_COOL, Game3v3Camp.S_CAMP_WARM, Game3v3Camp.S_CAMP_WARM, Game3v3Camp.S_CAMP_COOL, Game3v3Camp.S_CAMP_WARM, Game3v3Camp.S_CAMP_COOL, Game3v3Camp.S_CAMP_WARM, Game3v3Camp.S_CAMP_COOL }, }; Random rd = new Random(); int index = rd.Next(0, 4); List <Game3v3Camp> games = camps[index], choose = new List <Game3v3Camp> { Game3v3Camp.S_CAMP_COOL, Game3v3Camp.S_CAMP_WARM }; Game3v3Camp player_camp = choose[rd.Next(2)]; List <Client> clients = new List <Client>(room.Clients); Shuffle.shuffle(ref clients); int player_index = 0; int computer_index = 1; bool warm_lord = false; for (int i = 0; i < room_players.Count; i++) { Player player = room_players[i]; player.Camp = games[i]; if (player.Camp == player_camp) { Client client = clients[player_index]; player_index++; if (client.UserID > 0) { client.Status = Client.GameStatus.online; } player.SceenName = client.Profile.NickName; player.Status = client.Status.ToString(); player.ClientId = client.UserID; } else { player.SceenName = string.Format("computer{0}", computer_index); computer_index++; player.Status = "bot"; player.ClientId = 0; } if (i == 0) { player.Role = "lord"; player.Next = room_players[i + 1].Name; } else if (i == 7) { player.Next = room_players[0].Name; } else { player.Next = room_players[i + 1].Name; } if (player.Camp == Game3v3Camp.S_CAMP_WARM && !warm_lord) { player.Role = "lord"; warm_lord = true; } if (player.GetRoleEnum() != Player.PlayerRole.Lord) { player.Role = "loyalist"; } room.BroadcastProperty(player, "Camp"); room.BroadcastProperty(player, "Role"); } }
private static void ChangeSkin(Room room, Player player, int rate) { //机器人换皮肤 if (player != null && player.ClientId < 0 && Shuffle.random(1, rate)) { List <DataRow> data1 = Engine.GetGeneralSkin(player.ActualGeneral1, room.Setting.GameMode); bool head = data1.Count > 1 && (string.IsNullOrEmpty(player.ActualGeneral2) || Shuffle.random(1, 2)); if (head) { string name = player.ActualGeneral1; Random ra = new Random(); int result = ra.Next(0, data1.Count); if (result != player.HeadSkinId) { player.HeadSkinId = result; if (player.General1Showed) { room.BroadcastProperty(player, "HeadSkinId"); } } } if (!string.IsNullOrEmpty(player.ActualGeneral2) && (!head || Shuffle.random(1, 2))) { List <DataRow> data2 = Engine.GetGeneralSkin(player.ActualGeneral2, room.Setting.GameMode); if (data2.Count > 1) { Random ra = new Random(); int result = ra.Next(0, data2.Count); if (result != player.DeputySkinId) { player.DeputySkinId = result; if (player.General2Showed) { room.BroadcastProperty(player, "DeputySkinId"); } } } } } }
public void AddShuffle(Shuffle newShuffle) { _context.Add(newShuffle); }
public static void OnPlayStart(Room room, Player player) { List <Client> ais = new List <Client>(); foreach (Client client in room.Clients) { if (client.UserId < 0) { ais.Add(client); } } if (ais.Count == 0) { return; } DataRow[] rows = Engine.GetStarPlayLines(); foreach (DataRow row in rows) { string str = row["skills"].ToString(); bool check = false; string[] skills = str.Split('|'); foreach (string skill in skills) { bool _check = true; foreach (string _skill in skill.Split('+')) { if (!RoomLogic.PlayerHasShownSkill(room, player, _skill)) { _check = false; break; } } if (_check) { check = true; break; } } if (check) { foreach (Client ai in ais) { //几率1/3聊天 if (Shuffle.random(1, 3)) { //50%随机是发言还是表情 bool speak = Shuffle.random(1, 2); if (room.Setting.SpeakForbidden) { speak = false; } //50%随机 int num = Shuffle.random(1, 2) ? 1 : 2; if (room.GetClient(player) == ai) { if (speak) { string message = row[string.Format("self_lines{0}", num)].ToString(); if (!string.IsNullOrEmpty(message)) { room.Speak(ai, message); } } else { string messages = row[string.Format("self_emotion{0}", num)].ToString(); if (!string.IsNullOrEmpty(messages)) { string[] ms = messages.Split('/'); room.Emotion(ai, ms[0], ms[1]); } } } else { if (speak) { string message = row[string.Format("lines{0}", num)].ToString(); if (!string.IsNullOrEmpty(message)) { room.Speak(ai, message); } } else { string messages = row[string.Format("emotion{0}", num)].ToString(); if (!string.IsNullOrEmpty(messages)) { string[] ms = messages.Split('/'); room.Emotion(ai, ms[0], ms[1]); } } } } } } } }
public override void Assign(Room room) { AssignGeneralsForPlayers(room, out Dictionary <Player, List <string> > options); List <Interactivity> receivers = new List <Interactivity>(); foreach (Player player in options.Keys) { player.SetTag("generals", JsonUntity.Object2Json(options[player])); List <string> args = new List <string> { player.Name, //操作的玩家名 string.Empty, //原因 JsonUntity.Object2Json(options[player]), //备选武将 false.ToString(), //是否单将 true.ToString(), //是否可以武将转换SP false.ToString() //双将时是否匹配相同国籍 }; Interactivity client = room.GetInteractivity(player); if (client != null && !receivers.Contains(client)) { client.CommandArgs = args; receivers.Add(client); } } List <Player> players = room.Players; Countdown countdown = new Countdown { Max = room.Setting.GetCommandTimeout(CommandType.S_COMMAND_CHOOSE_GENERAL, ProcessInstanceType.S_CLIENT_INSTANCE), Type = Countdown.CountdownType.S_COUNTDOWN_USE_SPECIFIED }; room.NotifyMoveFocus(players, countdown); room.DoBroadcastRequest(receivers, CommandType.S_COMMAND_CHOOSE_GENERAL); room.DoBroadcastNotify(CommandType.S_COMMAND_UNKNOWN, new List <string> { false.ToString() }); foreach (Player player in options.Keys) { player.RemoveTag("generals"); if (!string.IsNullOrEmpty(player.General1)) { continue; } bool success = true; Interactivity client = room.GetInteractivity(player); List <string> reply = client?.ClientReply; if (client == null || !client.IsClientResponseReady || reply == null || reply.Count == 0 || string.IsNullOrEmpty(reply[0])) { success = false; } else { string generalName = reply[0]; string[] generals = generalName.Split('+'); if (generals.Length != 2 || (!options[player].Contains(generals[0]) && room.GetClient(player).UserRight < 3) || (!options[player].Contains(generals[1]) && room.GetClient(player).UserRight < 3) || !SetPlayerGeneral(room, player, generals[0], true) || !SetPlayerGeneral(room, player, generals[1], false)) { success = false; } } if (!success) { SetPlayerGeneral(room, player, options[player][0], true); SetPlayerGeneral(room, player, options[player][1], false); } } foreach (Player player in players) { List <string> names = new List <string>(); if (!string.IsNullOrEmpty(player.General1)) { string name = player.General1; names.Add(name); player.General1 = "anjiang"; room.BroadcastProperty(player, "General1"); room.NotifyProperty(room.GetClient(player), player, "ActualGeneral1"); foreach (Client p in room.Clients) { if (p != room.GetClient(player)) { room.NotifyProperty(p, player, "Kingdom", "god"); } } } if (!string.IsNullOrEmpty(player.General2)) { string name = player.General2; names.Add(name); player.General2 = "anjiang"; room.BroadcastProperty(player, "General2"); room.NotifyProperty(room.GetClient(player), player, "ActualGeneral2"); } room.SetTag(player.Name, names); room.HandleUsedGeneral(names[0]); room.HandleUsedGeneral(names[1]); if (reserved.TryGetValue(player, out List <string> p_reserved) && (p_reserved.Contains(names[0]) || p_reserved.Contains(names[1]))) { LogMessage reserved_log = new LogMessage(); reserved_log.Type = "#reserved_pick"; reserved_log.From = player.Name; room.SendLog(reserved_log); } if (!options[player].Contains(names[0]) || !options[player].Contains(names[1])) { LogMessage log = new LogMessage(); log.Type = "#cheat_pick"; log.From = player.Name; room.SendLog(log); } } //选择国籍 receivers.Clear(); players.Clear(); List <string> prompts = new List <string> { "@choose-kingdom" }; Dictionary <Player, List <string> > kingdoms = new Dictionary <Player, List <string> >(); foreach (Player player in room.Players) { List <string> choices = new List <string> { "careerist" }; General g1 = Engine.GetGeneral(player.ActualGeneral1, Name); General g2 = Engine.GetGeneral(player.ActualGeneral2, Name); foreach (General.KingdomENUM kingdom in g1.Kingdom) { if (!choices.Contains(General.GetKingdom(kingdom))) { choices.Add(General.GetKingdom(kingdom)); } } foreach (General.KingdomENUM kingdom in g2.Kingdom) { if (!choices.Contains(General.GetKingdom(kingdom))) { choices.Add(General.GetKingdom(kingdom)); } } kingdoms.Add(player, choices); List <string> args = new List <string> { player.Name, "Kingdom", string.Join("+", choices), JsonUntity.Object2Json(prompts) }; Interactivity client = room.GetInteractivity(player); if (client != null && !receivers.Contains(client)) { client.CommandArgs = args; receivers.Add(client); } players.Add(player); } countdown = new Countdown { Max = room.Setting.GetCommandTimeout(CommandType.S_COMMAND_MULTIPLE_CHOICE, ProcessInstanceType.S_CLIENT_INSTANCE), Type = Countdown.CountdownType.S_COUNTDOWN_USE_SPECIFIED }; room.NotifyMoveFocus(players, countdown); room.DoBroadcastRequest(receivers, CommandType.S_COMMAND_MULTIPLE_CHOICE); room.DoBroadcastNotify(CommandType.S_COMMAND_UNKNOWN, new List <string> { false.ToString() }); foreach (Player player in players) { string answer = string.Empty; Interactivity interactivity = room.GetInteractivity(player); if (interactivity != null) { List <string> clientReply = interactivity.ClientReply; if (clientReply != null && clientReply.Count > 0) { answer = clientReply[0]; } } List <string> choices = kingdoms[player]; if (string.IsNullOrEmpty(answer) || !choices.Contains(answer)) { Shuffle.shuffle(ref choices); answer = choices[0]; } if (answer != "careerist") { player.Kingdom = player.Role = answer; room.NotifyProperty(room.GetClient(player), player, "Kingdom"); } else { player.Kingdom = "god"; player.Role = answer; room.NotifyProperty(room.GetClient(player), player, "Role"); } } //君主转换 if (room.Setting.LordConvert) { room.AskForLordConvert(); } foreach (Player player in players) { General general1 = Engine.GetGeneral(player.ActualGeneral1, room.Setting.GameMode); General general2 = Engine.GetGeneral(player.ActualGeneral2, room.Setting.GameMode); if (general1.CompanionWith(player.ActualGeneral2, Name)) { player.AddMark("CompanionEffect"); } int max_hp = general1.GetMaxHpHead() + general2.GetMaxHpDeputy(); player.SetMark("HalfMaxHpLeft", max_hp % 2); player.MaxHp = max_hp / 2; player.Hp = player.MaxHp; room.BroadcastProperty(player, "MaxHp"); room.BroadcastProperty(player, "Hp"); } }
// //POST: //AddNewUser public async Task <ActionResult> AddNewUser(PostUsersViewModel model) { if (ModelState.IsValid) { using (DBModel db = new DBModel()) { //Check if Email or Username provided Exists var CheckEmailExists = db.AspNetUsers.Any(i => i.Email == model.Email || i.UserName == model.Email); var _action = "AddNewUser"; if (CheckEmailExists) { //Return error return(Json("User exists! Unable to create new user", JsonRequestBehavior.AllowGet)); } else { //Create User var PasswordResetCode = OTPGenerator.GetUniqueKey(6); string mixedOriginal = Shuffle.StringMixer(PasswordResetCode); var user = new ApplicationUser { UserName = model.Email, Email = model.Email, CompanyName = model.CompanyName, PhoneNumber = model.PhoneNumber, StaffNumber = model.StaffNumber, PasswordResetCode = Functions.GenerateMD5Hash(mixedOriginal), LastPasswordChangedDate = DateTime.Now }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { //Add EMT user role UserManager.AddToRole(user.Id, model.UserRole); //Send Success Email to reset password with OTP string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = Url.Action("ResetPassword", "Account", null, Request.Url.Scheme); var PasswordResetMessageBody = "Dear " + model.CompanyName + ", <br/><br/> You have been created as a user at Global Markets Onboarding Portal." + "<a href=" + callbackUrl + "> Click here to reset your password. </a> Your Reset Code is: " + mixedOriginal + " <br/><br/>" + "Kind Regards,<br/><img src=\"https://e-documents.stanbicbank.co.ke/Content/images/EmailSignature.png\"/>"; var PasswordResetEmail = MailHelper.SendMailMessage(MailHelper.EmailFrom, model.Email, "New User: Password Reset", PasswordResetMessageBody); if (PasswordResetEmail == true) { //Log email sent notification LogNotification.AddSucsessNotification(MailHelper.EmailFrom, PasswordResetMessageBody, model.Email, _action); } else { //Log Email failed notification LogNotification.AddFailureNotification(MailHelper.EmailFrom, PasswordResetMessageBody, model.Email, _action); } return(Json("success", JsonRequestBehavior.AllowGet)); } else { return(Json("Unable to create new user", JsonRequestBehavior.AllowGet)); } } } } else { return(Json("Invalid form input. Unable to create new user", JsonRequestBehavior.AllowGet)); } }
private void OnShuffleChanged(Shuffle state) { m_eventManager.QueueEvent(new ShuffleChanged(state)); }
public Game() { GameDeck = new Shuffle().ShuffleDeck(new Deck.Deck().NewDeck()); Players.Add(Dealer); Players.Add(Player1); }
public void PlaceItems() { FileUtils.GetItemsFromJson("Data//Items.json", out List <Item> items); FileUtils.GetItemsFromJson("Data//Mantras.json", out List <Item> mantras); FileUtils.GetItemsFromJson("Data//ShopOnlyItems.json", out List <Item> shopOnlyItems); StartingWeapon = ItemPool.GetAndRemove(ItemID.Whip, items); //Places weights at a starting shop since they are needed for alot of early items //this means that player will not have to rely on drops or weights from pots GetLocation("Nebur Shop 1").PlaceItem(ItemPool.GetAndRemove(ItemID.Weights, shopOnlyItems)); if (Settings.ShopPlacement != ShopPlacement.Original) { //these locations cant be included properly atm since the reason the shop switches is unknown GetLocation("Hiner Shop 3").PlaceItem(ItemPool.GetAndRemove(ItemID.Map1, items)); GetLocation("Hiner Shop 4").PlaceItem(ItemPool.GetAndRemove(ItemID.Map2, items)); } shopOnlyItems = Shuffle.FisherYates(shopOnlyItems, random); //place the weights and ammo in shops first since they can only be in shops PlaceShopItems(shopOnlyItems, items); //create a list of the items we want to place that are accessible from the start List <Item> earlyItems = new List <Item>(); if (!Settings.RandomGrail) { earlyItems.Add(ItemPool.GetAndRemove(ItemID.HolyGrail, items)); } if (!Settings.RandomScanner && Settings.ShopPlacement != ShopPlacement.Original) { earlyItems.Add(ItemPool.GetAndRemove(ItemID.HandScanner, items)); } if (!Settings.RandomCodices && Settings.ShopPlacement != ShopPlacement.Original) { earlyItems.Add(ItemPool.GetAndRemove(ItemID.Codices, items)); } if (!Settings.RandomFDC && Settings.ShopPlacement != ShopPlacement.Original) { earlyItems.Add(ItemPool.GetAndRemove(ItemID.FutureDevelopmentCompany, items)); } earlyItems = Shuffle.FisherYates(earlyItems, random); RandomiseWithChecks(GetUnplacedLocations(), earlyItems, new List <Item>()); //split the remaining item it required/non required List <Item> requiredItems = ItemPool.GetRequiredItems(items); List <Item> nonRequiredItems = ItemPool.GetNonRequiredItems(items); requiredItems = Shuffle.FisherYates(requiredItems, random); nonRequiredItems = Shuffle.FisherYates(nonRequiredItems, random); mantras = Shuffle.FisherYates(mantras, random); //place mantras if they are not fully randomised PlaceMantras(mantras, requiredItems); //place required items RandomiseAssumedFill(GetUnplacedLocations(), requiredItems); //place non requires items RandomiseWithoutChecks(GetUnplacedLocations(), nonRequiredItems); }
public int CreateUnique(int bNum) { VillageBuildingList.Building[] posibleBuildings = VB.buildingList[VB.buildingList.Length - 1].buildings; int num = 0; Vector2 size = new Vector2(1, 1); if (bNum == 1 && Size > 150f) { return(0); } switch (bNum) { case 1: size = posibleBuildings[1].objectSize; num = 1; break; case 2: size = posibleBuildings[2].objectSize; num = 2; break; case 3: size = posibleBuildings[0].objectSize; num = 0; break; } List <Coord> edges = new List <Coord>(); for (int x = 0; x < interior.GetLength(0); x++) { for (int y = 0; y < interior.GetLength(1); y++) { if (interior[x, y] == Space.edge) { edges.Add(new Coord(x, y)); } } } int breakLoop = 0; shuffledCoords = new Queue <Coord>(Shuffle.ShuffleArray(edges.ToArray())); for (int k = 0; k < edges.Count; k++) { Coord rnd = GetRandomCoord(); bool[] b = FreeSpace(rnd.x, rnd.y, size); //if the building fits in the space if (b[0]) { GameObject h; if (b[3]) { //spawn that building in the space h = Instantiate(posibleBuildings[num].prefab, new Vector3(rnd.x * 2.5f + MinX * 10f + (b[1] ? -size.x - (size.x % 2 == 1 ? .5f : 0) : size.x + (size.x % 2 == 1 ? .5f : 0)), (animate? -45 : 0), rnd.y * 2.5f + MinY * 10f + (b[2] ? -size.y + (size.y % 2 == 1 ? .5f : 0) : size.y - (size.y % 2 == 1 ? .5f : 0))) + (b[1] ? posibleBuildings[num].posX : posibleBuildings[num].negX), Quaternion.Euler(FindEdgeDirection(rnd.x, rnd.y)), transform); } else { h = Instantiate(posibleBuildings[num].prefab, new Vector3(rnd.x * 2.5f + MinX * 10f + (b[1] ? -size.y + (size.y % 2 == 1 ? .5f : 0) : size.y - (size.y % 2 == 1 ? .5f : 0)), (animate? -45 : 0), rnd.y * 2.5f + MinY * 10f + (b[2] ? -size.x + (size.x % 2 == 1 ? .5f : 0) : size.x - (size.x % 2 == 1 ? .5f : 0))) + (b[2] ? posibleBuildings[num].posY : posibleBuildings[num].negY), Quaternion.Euler(FindEdgeDirection(rnd.x, rnd.y)), transform); } //if (!b[3]) //{ // h.transform.Rotate(posibleBuildings[num].rotationSide, -90f); //} if (num == 2) { h.name = "Barracks"; } if (num == 1) { functionType = Function.Castle; } if (animate) { Raise rise = h.AddComponent <Raise>(); rise.timeToWait = RandomNumber.Range(0f, 2f);//((x + y) / 4f) / 10f; RunAnimation += rise.StartRaise; } BuildingVariation v = h.transform.GetChild(0).GetComponent <BuildingVariation>(); if (v) { v.roofColor = identifier.roof; v.woodColor = identifier.wood; v.Customize(); } //assign all the tiles as taken for (int i = 0; i < (b[3] ? size.x : size.y); i++) { for (int j = 0; j < (b[3] ? size.y : size.x); j++) { interior[(b[1] ? rnd.x - i : rnd.x + i), (b[2] ? rnd.y - j : rnd.y + j)] = Space.taken; } } return(bNum); } if (breakLoop > 100) { return(-1); } } //for (int x = 0; x < interior.GetLength(0); x++) //{ // for (int y = 0; y < interior.GetLength(1); y++) // { // if ((interior[x, y] == Space.edge && posibleBuildings[num].SpawnsOnEdge) || (interior[x, y] == Space.corner && posibleBuildings[num].SpawnInCorner)) // { // bool[] b = FreeSpace(x, y, size); // //if the building fits in the space // if (b[0]) // { // GameObject h; // if (b[3]) // //spawn that building in the space // h = Instantiate(posibleBuildings[num].prefab, new Vector3(x * 2.5f + MinX * 10f + (b[1] ? -size.x - (size.x % 2 == 1 ? .5f : 0) : size.x + (size.x % 2 == 1 ? .5f : 0)), -45, y * 2.5f + MinY * 10f + (b[2] ? -size.y + (size.y % 2 == 1 ? .5f : 0) : size.y - (size.y % 2 == 1 ? .5f : 0))) + (b[1] ? posibleBuildings[num].posX : posibleBuildings[num].negX), Quaternion.Euler(FindEdgeDirection(x, y)), transform); // else // h = Instantiate(posibleBuildings[num].prefab, new Vector3(x * 2.5f + MinX * 10f + (b[1] ? -size.y + (size.y % 2 == 1 ? .5f : 0) : size.y - (size.y % 2 == 1 ? .5f : 0)), -45, y * 2.5f + MinY * 10f + (b[2] ? -size.x + (size.x % 2 == 1 ? .5f : 0) : size.x - (size.x % 2 == 1 ? .5f : 0))) + (b[2] ? posibleBuildings[num].posY : posibleBuildings[num].negY), Quaternion.Euler(FindEdgeDirection(x, y)), transform); // //if (!b[3]) // //{ // // h.transform.Rotate(posibleBuildings[num].rotationSide, -90f); // //} // Raise rise = h.AddComponent<Raise>(); // if (num == 1) // functionType = Function.Castle; // rise.timeToWait = RandomNumber.Range(0f, 2f);//((x + y) / 4f) / 10f; // rise.StartRaise(); // BuildingVariation v = h.transform.GetChild(0).GetComponent<BuildingVariation>(); // if (v) // { // v.roofColor = identifier.roof; // v.woodColor = identifier.wood; // v.Customize(); // } // //assign all the tiles as taken // for (int i = 0; i < (b[3] ? size.x : size.y); i++) // { // for (int j = 0; j < (b[3] ? size.y : size.x); j++) // { // interior[(b[1] ? x - i : x + i), (b[2] ? y - j : y + j)] = Space.taken; // } // } // return bNum; // } // } // } //} return(0); }
private void AssignGeneralsForPlayers(Room room, out Dictionary <Player, List <string> > options) { options = new Dictionary <Player, List <string> >(); int max_choice = room.Setting.GeneralCount; List <string> generals = new List <string>(room.Generals); if (generals.Count < max_choice * room.Players.Count) { max_choice = generals.Count / room.Players.Count; } for (int i = 0; i < room.Clients.Count; i++) { Client client = room.Clients[i]; if (client.UserID < 0) { continue; } List <string> reserved_generals = client.GeneralReserved; if (reserved_generals == null || reserved_generals.Count == 0) { continue; } foreach (string general in reserved_generals) { for (int y = i + 1; y < room.Clients.Count; y++) { Client client2 = room.Clients[y]; if (client == client2 || client2.UserID < 0 || client2.GeneralReserved == null || client2.GeneralReserved.Count == 0) { continue; } if (client2.GeneralReserved.Contains(general)) { client.GeneralReserved.RemoveAll(t => t == general); client2.GeneralReserved.RemoveAll(t => t == general); } } } } foreach (Client client in room.Clients) { if (client.GeneralReserved != null && client.GeneralReserved.Count > 0 && client.GeneralReserved.Count <= 2) { foreach (Player p in room.Players) { if (p.ClientId == client.UserID) { options[p] = new List <string>(); foreach (string general in client.GeneralReserved) { if (generals.Contains(general)) { options[p].Add(general); generals.Remove(general); } } break; } } } client.GeneralReserved = null; } foreach (Player player in room.Players) { List <string> choices = new List <string>(); int adjust = options.ContainsKey(player) ? options[player].Count : 0; for (int i = adjust; i < max_choice; i++) { Shuffle.shuffle(ref generals); choices.Add(generals[0]); generals.RemoveAt(0); } if (options.ContainsKey(player)) { options[player].AddRange(choices); } else { options.Add(player, choices); } } }
//Spawns all the buildings public void Create() { //pull the list based upon what the function of the tile is. VillageBuildingList.Building[] posibleBuildings = VB.buildingList[(int)functionType - 1].buildings; //int temp = 11; List <Coord> cornerTiles = new List <Coord>(); List <Coord> edgeTiles = new List <Coord>(); List <Coord> interiorEdge = new List <Coord>(); for (int x = 0; x < interior.GetLength(0); x++) { for (int y = 0; y < interior.GetLength(1); y++) { if (interior[x, y] == Space.corner) { cornerTiles.Add(new Coord(x, y)); } if (interior[x, y] == Space.edge) { edgeTiles.Add(new Coord(x, y)); } if (interior[x, y] == Space.insideCorner) { interiorEdge.Add(new Coord(x, y)); } } } shuffledCoords = new Queue <Coord>(Shuffle.ShuffleArray(edgeTiles.ToArray())); //if its a castle, try the first two buildings first if (functionType == Function.Castle) { for (int k = 0; k < edgeTiles.Count; k++) { Coord rnd = GetRandomCoord(); for (int r = 0; r < 2; r++) { //take a random building object int num = r; Vector2 size = posibleBuildings[num].objectSize; if (!posibleBuildings[num].SpawnsOnEdge) { continue; } bool[] b = FreeSpace(rnd.x, rnd.y, size); //if the building fits in the space if (b[0]) { GameObject h; if (b[3]) { //spawn that building in the space h = Instantiate(posibleBuildings[num].prefab, new Vector3(rnd.x * 2.5f + MinX * 10f + (b[1] ? -size.x - (size.x % 2 == 1 ? .5f : 0) : size.x + (size.x % 2 == 1 ? .5f : 0)), (animate ? -45 : 0), rnd.y * 2.5f + MinY * 10f + (b[2] ? -size.y + (size.y % 2 == 1 ? .5f : 0) : size.y - (size.y % 2 == 1 ? .5f : 0))) + (b[1] ? posibleBuildings[num].posX : posibleBuildings[num].negX), Quaternion.Euler(FindEdgeDirection(rnd.x, rnd.y)), transform); } else { h = Instantiate(posibleBuildings[num].prefab, new Vector3(rnd.x * 2.5f + MinX * 10f + (b[1] ? -size.y + (size.y % 2 == 1 ? .5f : 0) : size.y - (size.y % 2 == 1 ? .5f : 0)), (animate ? -45 : 0), rnd.y * 2.5f + MinY * 10f + (b[2] ? -size.x + (size.x % 2 == 1 ? .5f : 0) : size.x - (size.x % 2 == 1 ? .5f : 0))) + (b[2] ? posibleBuildings[num].posY : posibleBuildings[num].negY), Quaternion.Euler(FindEdgeDirection(rnd.x, rnd.y)), transform); } //if (!b[3]) //{ // h.transform.Rotate(posibleBuildings[num].rotationSide, 90f); //} if (animate) { Raise rise = h.AddComponent <Raise>(); rise.timeToWait = RandomNumber.Range(2f, 5f); //((x + y) / 4f) / 10f; RunAnimation += rise.StartRaise; } BuildingVariation v = h.transform.GetChild(0).GetComponent <BuildingVariation>(); if (v) { v.roofColor = identifier.roof; v.woodColor = identifier.wood; v.Customize(); } //assign all the tiles as taken for (int i = 0; i < (b[3] ? size.x : size.y); i++) { for (int j = 0; j < (b[3] ? size.y : size.x); j++) { interior[(b[1] ? rnd.x - i : rnd.x + i), (b[2] ? rnd.y - j : rnd.y + j)] = Space.taken; } } k = edgeTiles.Count; break; } } if (k == edgeTiles.Count) { break; } } } //do the corners shuffledCoords = new Queue <Coord>(Shuffle.ShuffleArray(cornerTiles.ToArray())); for (int k = 0; k < cornerTiles.Count; k++) { Coord rnd = GetRandomCoord(); if (interior[rnd.x, rnd.y] != Space.corner) { continue; } for (int r = 0; r < 100; r++) { //take a random building object int num = /*temp % posibleBuildings.Length;*/ RandomNumber.Range(0, posibleBuildings.Length); Vector2 size = posibleBuildings[num].objectSize; if (!posibleBuildings[num].SpawnInCorner) { continue; } bool[] b = FreeSpace(rnd.x, rnd.y, size); //if the building fits in the space if (b[0]) { GameObject h; if (b[3]) { //spawn that building in the space h = Instantiate(posibleBuildings[num].prefab, new Vector3(rnd.x * 2.5f + MinX * 10f + (b[1] ? -size.x - (size.x % 2 == 1 ? .5f : 0) : size.x + (size.x % 2 == 1 ? .5f : 0)), (animate ? -45 : 0), rnd.y * 2.5f + MinY * 10f + (b[2] ? -size.y + (size.y % 2 == 1 ? .5f : 0) : size.y - (size.y % 2 == 1 ? .5f : 0))) + (b[1] ? posibleBuildings[num].posX : posibleBuildings[num].negX), Quaternion.Euler(FindEdgeDirection(rnd.x, rnd.y)), transform); } else { h = Instantiate(posibleBuildings[num].prefab, new Vector3(rnd.x * 2.5f + MinX * 10f + (b[1] ? -size.y + (size.y % 2 == 1 ? .5f : 0) : size.y - (size.y % 2 == 1 ? .5f : 0)), (animate ? -45 : 0), rnd.y * 2.5f + MinY * 10f + (b[2] ? -size.x + (size.x % 2 == 1 ? .5f : 0) : size.x - (size.x % 2 == 1 ? .5f : 0))) + (b[2] ? posibleBuildings[num].posY : posibleBuildings[num].negY), Quaternion.Euler(FindEdgeDirection(rnd.x, rnd.y)), transform); } //if (!b[3]) //{ // h.transform.Rotate(posibleBuildings[num].rotationSide, -90f); //} if (animate) { Raise rise = h.AddComponent <Raise>(); rise.timeToWait = RandomNumber.Range(0f, 2f);//((x + y) / 4f) / 10f; RunAnimation += rise.StartRaise; } if (h.transform.childCount > 0) { BuildingVariation v = h.transform.GetChild(0).GetComponent <BuildingVariation>(); if (v) { v.roofColor = identifier.roof; v.woodColor = identifier.wood; v.Customize(); } } //assign all the tiles as taken for (int i = 0; i < (b[3] ? size.x : size.y); i++) { for (int j = 0; j < (b[3] ? size.y : size.x); j++) { interior[(b[1] ? rnd.x - i : rnd.x + i), (b[2] ? rnd.y - j : rnd.y + j)] = Space.taken; } } } } } //spawn corrners //for (int x = 0; x < interior.GetLength(0); x++) //{ // for (int y = 0; y < interior.GetLength(1); y++) // { // if (interior[x, y] == Space.corner) // { // //try 100 times to get a house that fits in the space // for (int r = 0; r < 100; r++) // { // //take a random building object // int num = /*temp % posibleBuildings.Length;*/RandomNumber.Range(0, posibleBuildings.Length); // Vector2 size = posibleBuildings[num].objectSize; // if (!posibleBuildings[num].SpawnInCorner) // continue; // bool[] b = FreeSpace(x, y, size); // //if the building fits in the space // if (b[0]) // { // GameObject h; // if (b[3]) // //spawn that building in the space // h = Instantiate(posibleBuildings[num].prefab, new Vector3(x * 2.5f + MinX * 10f + (b[1] ? -size.x - (size.x % 2 == 1 ? .5f : 0) : size.x + (size.x % 2 == 1 ? .5f : 0)), -45, y * 2.5f + MinY * 10f + (b[2] ? -size.y + (size.y % 2 == 1 ? .5f : 0) : size.y - (size.y % 2 == 1 ? .5f : 0))) + (b[1] ? posibleBuildings[num].posX : posibleBuildings[num].negX), Quaternion.Euler(FindEdgeDirection(x, y)), transform); // else // h = Instantiate(posibleBuildings[num].prefab, new Vector3(x * 2.5f + MinX * 10f + (b[1] ? -size.y + (size.y % 2 == 1 ? .5f : 0) : size.y - (size.y % 2 == 1 ? .5f : 0)), -45, y * 2.5f + MinY * 10f + (b[2] ? -size.x + (size.x % 2 == 1 ? .5f : 0) : size.x - (size.x % 2 == 1 ? .5f : 0))) + (b[2] ? posibleBuildings[num].posY : posibleBuildings[num].negY), Quaternion.Euler(FindEdgeDirection(x, y)), transform); // //if (!b[3]) // //{ // // h.transform.Rotate(posibleBuildings[num].rotationSide, -90f); // //} // Raise rise = h.AddComponent<Raise>(); // rise.timeToWait = RandomNumber.Range(0f, 2f);//((x + y) / 4f) / 10f; // rise.StartRaise(); // BuildingVariation v = h.transform.GetChild(0).GetComponent<BuildingVariation>(); // if (v) // { // v.roofColor = identifier.roof; // v.woodColor = identifier.wood; // v.Customize(); // } // //assign all the tiles as taken // for (int i = 0; i < (b[3] ? size.x : size.y); i++) // { // for (int j = 0; j < (b[3] ? size.y : size.x); j++) // { // interior[(b[1] ? x - i : x + i), (b[2] ? y - j : y + j)] = Space.taken; // } // } // } // } // } // } //} shuffledCoords = new Queue <Coord>(Shuffle.ShuffleArray(edgeTiles.ToArray())); //do the edges for (int k = 0; k < edgeTiles.Count; k++) { Coord rnd = GetRandomCoord(); for (int r = 0; r < 100; r++) { //take a random building object int num = /*temp % posibleBuildings.Length;*/ RandomNumber.Range(0, posibleBuildings.Length); Vector2 size = posibleBuildings[num].objectSize; if (!posibleBuildings[num].SpawnsOnEdge) { continue; } bool[] b = FreeSpace(rnd.x, rnd.y, size); //if the building fits in the space if (b[0]) { GameObject h; if (b[3]) { //spawn that building in the space h = Instantiate(posibleBuildings[num].prefab, new Vector3(rnd.x * 2.5f + MinX * 10f + (b[1] ? -size.x - (size.x % 2 == 1 ? .5f : 0) : size.x + (size.x % 2 == 1 ? .5f : 0)), (animate ? -45 : 0), rnd.y * 2.5f + MinY * 10f + (b[2] ? -size.y + (size.y % 2 == 1 ? .5f : 0) : size.y - (size.y % 2 == 1 ? .5f : 0))) + (b[1] ? posibleBuildings[num].posX : posibleBuildings[num].negX), Quaternion.Euler(FindEdgeDirection(rnd.x, rnd.y)), transform); } else { h = Instantiate(posibleBuildings[num].prefab, new Vector3(rnd.x * 2.5f + MinX * 10f + (b[1] ? -size.y + (size.y % 2 == 1 ? .5f : 0) : size.y - (size.y % 2 == 1 ? .5f : 0)), (animate ? -45 : 0), rnd.y * 2.5f + MinY * 10f + (b[2] ? -size.x + (size.x % 2 == 1 ? .5f : 0) : size.x - (size.x % 2 == 1 ? .5f : 0))) + (b[2] ? posibleBuildings[num].posY : posibleBuildings[num].negY), Quaternion.Euler(FindEdgeDirection(rnd.x, rnd.y)), transform); } //if (!b[3]) //{ // h.transform.Rotate(posibleBuildings[num].rotationSide, 90f); //} if (animate) { Raise rise = h.AddComponent <Raise>(); rise.timeToWait = RandomNumber.Range(2f, 5f); //((x + y) / 4f) / 10f; RunAnimation += rise.StartRaise; } if (h.transform.childCount > 0) { BuildingVariation v = h.transform.GetChild(0).GetComponent <BuildingVariation>(); if (v) { v.roofColor = identifier.roof; v.woodColor = identifier.wood; v.Customize(); } } //assign all the tiles as taken for (int i = 0; i < (b[3] ? size.x : size.y); i++) { for (int j = 0; j < (b[3] ? size.y : size.x); j++) { interior[(b[1] ? rnd.x - i : rnd.x + i), (b[2] ? rnd.y - j : rnd.y + j)] = Space.taken; } } } } } ////spawns edges //for (int x = 0; x < interior.GetLength(0); x++) //{ // for (int y = 0; y < interior.GetLength(1); y++) // { // if (interior[x, y] == Space.edge) // { // //try 100 times to get a house that fits in the space // for (int r = 0; r < 100; r++) // { // //take a random building object // int num = /*temp % posibleBuildings.Length;*/RandomNumber.Range(0, posibleBuildings.Length); // Vector2 size = posibleBuildings[num].objectSize; // if (!posibleBuildings[num].SpawnsOnEdge) // continue; // bool[] b = FreeSpace(x, y, size); // //if the building fits in the space // if (b[0]) // { // GameObject h; // if (b[3]) // //spawn that building in the space // h = Instantiate(posibleBuildings[num].prefab, new Vector3(x * 2.5f + MinX * 10f + (b[1] ? -size.x - (size.x % 2 == 1 ? .5f : 0) : size.x + (size.x % 2 == 1 ? .5f : 0)), -45, y * 2.5f + MinY * 10f + (b[2] ? -size.y + (size.y % 2 == 1 ? .5f : 0) : size.y - (size.y % 2 == 1 ? .5f : 0))) + (b[1] ? posibleBuildings[num].posX : posibleBuildings[num].negX), Quaternion.Euler(FindEdgeDirection(x, y)), transform); // else // h = Instantiate(posibleBuildings[num].prefab, new Vector3(x * 2.5f + MinX * 10f + (b[1] ? -size.y + (size.y % 2 == 1 ? .5f : 0) : size.y - (size.y % 2 == 1 ? .5f : 0)), -45, y * 2.5f + MinY * 10f + (b[2] ? -size.x + (size.x % 2 == 1 ? .5f : 0) : size.x - (size.x % 2 == 1 ? .5f : 0))) + (b[2] ? posibleBuildings[num].posY : posibleBuildings[num].negY), Quaternion.Euler(FindEdgeDirection(x, y)), transform); // //if (!b[3]) // //{ // // h.transform.Rotate(posibleBuildings[num].rotationSide, 90f); // //} // Raise rise = h.AddComponent<Raise>(); // rise.timeToWait = RandomNumber.Range(2f, 5f); //((x + y) / 4f) / 10f; // rise.StartRaise(); // BuildingVariation v = h.transform.GetChild(0).GetComponent<BuildingVariation>(); // if (v) // { // v.roofColor = identifier.roof; // v.woodColor = identifier.wood; // v.Customize(); // } // //assign all the tiles as taken // for (int i = 0; i < (b[3] ? size.x : size.y); i++) // { // for (int j = 0; j < (b[3] ? size.y : size.x); j++) // { // interior[(b[1] ? x - i : x + i), (b[2] ? y - j : y + j)] = Space.taken; // } // } // } // } // } // } //} //if (globalBreeak > 20) //{ // Debug.Log("Broke", gameObject); // yield break; //} //if (transform.childCount < 2 && globalBreeak < 20) //{ // globalBreeak++; // Rebuild(); //} //for (int k = 0; k < edgeTiles.Count; k++) //{ // Coord rnd = GetRandomCoord(); // if(interior[rnd.x, rnd.y] == Space.edge) // { // bool XRotate = false; // if (rnd.x - 1 < 0 || rnd.x + 1 >= interior.GetLength(0)) // XRotate = true; // if (!XRotate) // { // if (interior[rnd.x - 1, rnd.y] == Space.free || interior[rnd.x - 1, rnd.y] == Space.outside) // XRotate = true; // if(interior[rnd.x + 1, rnd.y] == Space.free || interior[rnd.x + 1, rnd.y] == Space.outside) // XRotate = true; // } // Instantiate(VB.wall, new Vector3(rnd.x * 2.5f + MinX * 10f, 0, rnd.y * 2.5f + MinY * 10f), (XRotate ? Quaternion.Euler(new Vector3(0,-90,0)) : Quaternion.identity), transform); // } //} if (functionType != Function.Ruin) { foreach (Coord c in interiorEdge) { if (interior[c.x, c.y] == Space.insideCorner) { int sidesTaken = 0; if (interior[c.x + 1, c.y] == Space.taken) { sidesTaken++; } if (interior[c.x - 1, c.y] == Space.taken) { sidesTaken++; } if (interior[c.x, c.y + 1] == Space.taken) { sidesTaken++; } if (interior[c.x, c.y - 1] == Space.taken) { sidesTaken++; } if (sidesTaken == 2) { GameObject h = Instantiate(VB.cornerWall, new Vector3(c.x * 2.5f + MinX * 10f, (animate? -25f:0), c.y * 2.5f + MinY * 10f), Quaternion.identity, transform); if (animate) { Raise rise = h.AddComponent <Raise>(); rise.timeToWait = RandomNumber.Range(0f, 2f);//((x + y) / 4f) / 10f; RunAnimation += rise.StartRaise; } } } } } }
public override History fit(Dictionary <string, Array> x = null, Dictionary <string, Array> y = null, int batch_size = 32, int epochs = 1, int verbose = 1, CallbackList callbacks = null, double validation_split = 0, IList <Dictionary <string, Array> > validation_data = null, Shuffle shuffle = Shuffle.True, Dictionary <string, Dictionary <string, double> > class_weight = null, Dictionary <string, Array> sample_weight = null, int initial_epoch = 0, object kwargs = null) { //"""Trains the model for a fixed number of epochs. //# Arguments // x: input data, as a Numpy array or list of Numpy arrays // (if the model has multiple inputs). // y: labels, as a Numpy array. // batch_size: integer.Number of samples per gradient update. // epochs: integer, the number of epochs to train the model. // verbose: 0 for no logging to stdout, // 1 for progress bar logging, 2 for one log line per epoch. // callbacks: list of `keras.callbacks.Callback` instances. // List of callbacks to apply during training. // See[callbacks](/callbacks). // validation_split: float (0. < x< 1). // Fraction of the data to use as held-out validation data. // validation_data: tuple (x_val, y_val) or tuple // (x_val, y_val, val_sample_weights) to be used as held-out // validation data.Will override validation_split. // shuffle: boolean or str (for "batch"). // Whether to shuffle the samples at each epoch. // "batch" is a special option for dealing with the // limitations of HDF5 data; it shuffles in batch-sized chunks. // class_weight: dictionary mapping classes to a weight value, // used for scaling the loss function (during training only). // sample_weight: Numpy array of weights for // the training samples, used for scaling the loss function // (during training only). You can either pass a flat(1D) // Numpy array with the same length as the input samples // (1:1 mapping between weights and samples), // or in the case of temporal data, // you can pass a 2D array with shape(samples, sequence_length), // to apply a different weight to every timestep of every sample. // In this case you should make sure to specify // sample_weight_mode= "temporal" in compile(). // initial_epoch: epoch at which to start training // (useful for resuming a previous training run) //# Returns // A `History` object. Its `History.history` attribute is // a record of training loss values and metrics values // at successive epochs, as well as validation loss values // and validation metrics values (if applicable). //# Raises // RuntimeError: if the model was never compiled. //""" if (this.model == null) { throw new InvalidOperationException("The model needs to be compiled before being used."); } return(model.fit(x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, kwargs)); }
public void BlackjackShuffleTransactionTest_BasicDeck() { // NOTE: A game transaction using the basic (52-card) deck requires no explicit instantiation of the deck // by the client code; a basic deck is the default Instance. // arrange List<Player> players = new List<Player>(); Player alex = new Player { Name = "Alex" }; Player bill = new Player { Name = "Bill" }; Player charlie = new Player { Name = "Charlie" }; players.Add(alex); players.Add(bill); players.Add(charlie); Shuffle shuffle = new Shuffle(bill); // act shuffle.Execute(); // assert Assert.IsTrue(IsDeckShuffled(Deck.Instance)); }
public void Activate(object parameter, Dictionary <string, object> state) { //App.Current.Suspending += ForegroundApp_Suspending; //App.Current.Resuming += ForegroundApp_Resuming; index = CurrentSongIndex; if (index > -1) { SongItem song = Library.Current.NowPlayingList.ElementAt(index); CurrentNr = index + 1; SongsCount = Library.Current.NowPlayingList.Count; songId = song.SongId; Title = song.Title; Artist = song.Artist; Album = song.Album; fromDB = true; Rating = song.Rating; //PlaybackRate = 100.0; SetCover(song.Path); SetupTimer(); RepeatButtonContent = Repeat.CurrentStateContent(); RepeatButtonForeground = Repeat.CurrentStateColor(); ShuffleButtonForeground = Shuffle.CurrentStateColor(); if (IsMyBackgroundTaskRunning) { //Library.Current.Save("BG running"); AddMediaPlayerEventHandlers(); if (BackgroundMediaPlayer.Current.CurrentState == MediaPlayerState.Playing) { PlayButtonContent = "\uE17e\uE103";//pause } object r = ApplicationSettingsHelper.ReadResetSettingsValue(AppConstants.ResumePlayback); if (r != null) { SendMessage(AppConstants.ResumePlayback); TimeSpan t = BackgroundMediaPlayer.Current.NaturalDuration; double absvalue = (int)Math.Round(t.TotalSeconds - 0.5, MidpointRounding.AwayFromZero); ProgressBarMaxValue = absvalue; EndTime = BackgroundMediaPlayer.Current.NaturalDuration; PlaybackRate = BackgroundMediaPlayer.Current.PlaybackRate * 100.0; } else if (NextPlayer.Common.SuspensionManager.SessionState.ContainsKey("lyrics"))//mozna chyba zmienic na Dict<> state { NextPlayer.Common.SuspensionManager.SessionState.Remove("lyrics"); } else if (NextPlayer.Common.SuspensionManager.SessionState.ContainsKey("nplist"))//mozna chyba zmienic na Dict<> state { NextPlayer.Common.SuspensionManager.SessionState.Remove("nplist"); } else if (NextPlayer.Common.SuspensionManager.SessionState.ContainsKey("mainpage"))//mozna chyba zmienic na Dict<> state { NextPlayer.Common.SuspensionManager.SessionState.Remove("mainpage"); TimeSpan t = BackgroundMediaPlayer.Current.NaturalDuration; double absvalue = (int)Math.Round(t.TotalSeconds - 0.5, MidpointRounding.AwayFromZero); ProgressBarMaxValue = absvalue; EndTime = BackgroundMediaPlayer.Current.NaturalDuration; PlaybackRate = BackgroundMediaPlayer.Current.PlaybackRate * 100.0; } else { SendMessage(AppConstants.NowPlayingListChanged); SendMessage(AppConstants.StartPlayback, CurrentSongIndex); } } else { if (NextPlayer.Common.SuspensionManager.SessionState.ContainsKey("mainpage")) { NextPlayer.Common.SuspensionManager.SessionState.Remove("mainpage"); } object r = ApplicationSettingsHelper.ReadResetSettingsValue(AppConstants.ResumePlayback); //if (r != null) //{ // StartBackgroundAudioTask(AppConstants.ResumePlayback, CurrentSongIndex); //} //else //{ StartBackgroundAudioTask(AppConstants.StartPlayback, CurrentSongIndex); //} } StartTimer(); } else { navigationService.NavigateTo(ViewNames.MainView); } //if (parameter != null) //{ // if (parameter.GetType() == typeof(int)) // { // songId = (int)parameter; // } //} }
public void BlackjackShuffleTransactionTest_PokerDeck() { // arrange Deck.Instance = DeckFactory.CreatePokerDeck(); List<Player> players = new List<Player>(); Player alex = new Player { Name = "Alex" }; Player bill = new Player { Name = "Bill" }; Player charlie = new Player { Name = "Charlie" }; players.Add(alex); players.Add(bill); players.Add(charlie); Shuffle shuffle = new Shuffle(bill); // act shuffle.Execute(); // assert Assert.IsTrue(IsDeckShuffled(Deck.Instance)); }
public override void Assign(Room room) { System.Threading.Thread.Sleep(1000); //先确定两边主公 foreach (Player lord in room.Players) { if (lord.GetRoleEnum() == Player.PlayerRole.Lord) { if (lord.Camp == Game3v3Camp.S_CAMP_COOL) { lord.General1 = lord.ActualGeneral1 = "caocao_jx"; } else { lord.General1 = lord.ActualGeneral1 = "yuanshao"; } General lord_gen = Engine.GetGeneral(lord.General1, room.Setting.GameMode); lord.PlayerGender = lord_gen.GeneralGender; lord.Kingdom = lord_gen.Kingdom; lord.General1Showed = true; room.BroadcastProperty(lord, "General1"); room.BroadcastProperty(lord, "PlayerGender"); room.NotifyProperty(room.GetClient(lord), lord, "ActualGeneral1"); room.BroadcastProperty(lord, "Kingdom"); room.BroadcastProperty(lord, "General1Showed"); foreach (string skill in Engine.GetGeneralSkills(lord.General1, Name, true)) { room.AddPlayerSkill(lord, skill); Skill s = Engine.GetSkill(skill); if (s != null && s.SkillFrequency == Frequency.Limited && !string.IsNullOrEmpty(s.LimitMark)) { room.SetPlayerMark(lord, s.LimitMark, 1); } } room.SendPlayerSkillsToOthers(lord, true); //技能预亮 lord.SetSkillsPreshowed("hd"); room.NotifyPlayerPreshow(lord); } } System.Threading.Thread.Sleep(1000); //为其余玩家分配武将 List <string> generals = room.Generals, warms = new List <string>(), cools = new List <string>(); generals.Remove("caocao_jx"); generals.Remove("yuanshao"); foreach (string general in generals) { General gen = Engine.GetGeneral(general, room.Setting.GameMode); if (gen.Kingdom == "wei") { cools.Add(general); } else { warms.Add(general); } } Shuffle.shuffle(ref warms); Shuffle.shuffle(ref cools); Dictionary <Player, List <string> > options = new Dictionary <Player, List <string> >(); foreach (Player player in room.Players) { if (player.GetRoleEnum() == Player.PlayerRole.Lord) { continue; } List <string> choices = new List <string>(); if (player.Camp == Game3v3Camp.S_CAMP_COOL) { choices.Add(cools[0]); cools.RemoveAt(0); choices.Add(cools[0]); cools.RemoveAt(0); } else { choices.Add(warms[0]); warms.RemoveAt(0); choices.Add(warms[0]); warms.RemoveAt(0); } options.Add(player, choices); } //玩家选将 List <Interactivity> receivers = new List <Interactivity>(); List <Player> players = new List <Player>(); foreach (Player player in options.Keys) { if (player.GetRoleEnum() == Player.PlayerRole.Lord) { continue; } player.SetTag("generals", JsonUntity.Object2Json(options[player])); List <string> args = new List <string> { player.Name, string.Empty, JsonUntity.Object2Json(options[player]), true.ToString(), true.ToString(), false.ToString() }; Interactivity client = room.GetInteractivity(player); if (client != null && !receivers.Contains(client)) { client.CommandArgs = args; receivers.Add(client); } players.Add(player); } Countdown countdown = new Countdown { Max = room.Setting.GetCommandTimeout(CommandType.S_COMMAND_CHOOSE_GENERAL, ProcessInstanceType.S_CLIENT_INSTANCE), Type = Countdown.CountdownType.S_COUNTDOWN_USE_SPECIFIED }; room.NotifyMoveFocus(players, countdown); room.DoBroadcastRequest(receivers, CommandType.S_COMMAND_CHOOSE_GENERAL); room.DoBroadcastNotify(CommandType.S_COMMAND_UNKNOWN, new List <string> { false.ToString() }); //按武将强度排序 List <string> prefer_cools = new List <string> { "xunyou", "xunyu", "chengyu", "guojia", "liuye", "caoren", "guanyu_sp", "xuhuang_jx", "zhangliao_jx", "hanhaoshihuan", "yujin", "caohong" }; List <string> prefer_warms = new List <string> { "chunyuqiong", "xunchen", "shenpei", "liubei_gd", "chenlin_gd", "jvshou", "xuyou", "zhanghe_gd", "gaolan", "guotupangji", "tianfeng", "yanliangwenchou" }; //给AI和超时的玩家自动选择武将 foreach (Player player in options.Keys) { player.RemoveTag("generals"); if (string.IsNullOrEmpty(player.General1)) { string generalName = string.Empty; List <string> reply = room.GetInteractivity(player)?.ClientReply; bool success = true; if (reply == null || reply.Count == 0 || string.IsNullOrEmpty(reply[0])) { success = false; } else { generalName = reply[0]; } if (!success || (!options[player].Contains(generalName) && room.GetClient(player).UserRight < 3) || (player.Camp == Game3v3Camp.S_CAMP_COOL && Engine.GetGeneral(generalName, room.Setting.GameMode).Kingdom != "wei") || (player.Camp == Game3v3Camp.S_CAMP_WARM && Engine.GetGeneral(generalName, room.Setting.GameMode).Kingdom != "qun")) { if (player.Status == "bot") { List <string> prefers; if (player.Camp == Game3v3Camp.S_CAMP_COOL) { prefers = prefer_cools; } else { prefers = prefer_warms; } options[player].Sort((x, y) => { return(prefers.IndexOf(x) < prefers.IndexOf(y) ? -1 : 1); }); } generalName = options[player][0]; } player.General1 = generalName; player.ActualGeneral1 = generalName; player.Kingdom = Engine.GetGeneral(generalName, room.Setting.GameMode).Kingdom; player.General1Showed = true; } room.BroadcastProperty(player, "General1"); room.NotifyProperty(room.GetClient(player), player, "ActualGeneral1"); room.BroadcastProperty(player, "Kingdom"); room.BroadcastProperty(player, "General1Showed"); player.PlayerGender = Engine.GetGeneral(player.General1, room.Setting.GameMode).GeneralGender; room.BroadcastProperty(player, "PlayerGender"); player.SetSkillsPreshowed("hd"); room.NotifyPlayerPreshow(player); List <string> names = new List <string> { player.General1 }; room.SetTag(player.Name, names); room.HandleUsedGeneral(player.General1); } }
public void BlackjackIdentifyWinnerTransactionTest_BasicDeck() { // arrange List<Player> players = new List<Player>(); Player alex = new Player { Name = "Alex" }; Player bill = new Player { Name = "Bill" }; Player charlie = new Player { Name = "Charlie" }; players.Add(alex); players.Add(bill); players.Add(charlie); Shuffle shuffle = new Shuffle(bill); shuffle.Execute(); BlackjackDeal blackjackDeal = new BlackjackDeal(players, bill); Random rand = new Random(DateTime.Now.Millisecond); int upperBound = rand.Next(2,6); // deal anywhere from 2 to 5 cards to each player for (int i = 1; i <= upperBound; i++) { blackjackDeal.Execute(); } IdentifyWinnerBlackjack identWinner = new IdentifyWinnerBlackjack(players); // act identWinner.Execute(); // assert // verify that the winner(s) has/have the highest score Assert.AreEqual(players.Where(p => p.HandStatus == HandStatus.Winner).Select(p => p.Hand.Score).Max(), players.Select(p => p.Hand.Score).Max()); }
// Update is called once per frame void Update() { Shuffle.Shuffler(list); }
//public void SetShuffle(Shuffle shuffle) //{ // _shuffle = shuffle; // SetShuffleNumbers(_shuffle); //} //private void SetShuffleNumbers(Shuffle shuffle) //{ // _shuffle = shuffle; // List<ShuffleNumber> data = new List<ShuffleNumber>(); // if (_shuffle != null) // { // data = _numbrTumblrBusiness.GetShuffleNumbersByShuffleId(_shuffle.ShuffleID); // } // _shuffleNumbers.Clear(); // _shuffleNumbers.AddRange(data); //} public void RefreshData(Shuffle shuffle, NumberSet numberSet) { LoadShuffleNumbersData(shuffle, numberSet); }