public GameState PutOne(int Index, double Value) { var g = (GameState)MemberwiseClone(); g.Player1 = Player1.Clone(); g.Player2 = Player2.Clone(); g.Available = Available.ToArray(); g.Grid = new List <List <double> >(); for (int i = 0; i < 7; i++) { g.Grid.Add(Grid[i].ToList()); } g.Grid[Index][Available[Index]] = Value; var p = new GamePosition((byte)Index, (byte)Available[Index]); if (Value > 0) { ChainOfFour(g.Player1.Positions, g.Player1.Chains, p); g.Player1.Positions.Add(p); } else { ChainOfFour(g.Player2.Positions, g.Player2.Chains, p); g.Player2.Positions.Add(p); } g.BestChain = g.Player1.Chains.Any() ? g.Player1.Chains.Max(x => x.Chain.Count): 0; g.Available[Index]++; g.Round++; return(g); }
public static GamePosition minMax(GameLogic gameLogic, int mrX, int depth) { _mrX = mrX; Dictionary <int, Player> players = gameLogic.GameBoard.Players; _detectives = new HashSet <int>(players.Keys); _detectives.Remove(_mrX); //don't change the gameposition of the game being played - modify a copy GamePosition copyOfGamePosition = new GamePosition(gameLogic.GameBoard.Players); GamePosition bestMove = MaxMove(gameLogic, copyOfGamePosition, depth * players.Count + 1); List <int> moves = new List <int> (); GamePosition nextMove = bestMove; while (nextMove.Parent != null) { moves.Add(nextMove.Players[0].Location.Id); nextMove = nextMove.Parent; } StringBuilder movesString = new StringBuilder(); foreach (var move in moves) { movesString.Append(move + " "); } Debug.Log("moves: " + movesString); Debug.Log("best move: " + nextMove.Players[0].Location.Id); return(nextMove); }
public FourChain(GamePosition p1, GamePosition p2) { if (p2.Y < p1.Y) { (p1, p2) = (p2, p1); } Chain = new List <GamePosition>() { p1, p2 }; if (p1.X == p2.X) { Direction = FourDirection.Vertical; } else if (p1.Y == p2.Y) { Direction = FourDirection.Horizontal; } else if (p1.X > p2.X) { Direction = FourDirection.AntiSlash; } else { Direction = FourDirection.Slash; } }
public static GamePosition MinMove(GameLogic gameLogic, GamePosition gamePosition, int detectiveId, int depth) { int winningPlayerId; if (depth == 0 || gameLogic.winnerExists(gamePosition.Players, out winningPlayerId)) { return(gamePosition); } else { GamePosition potentialMove; GamePosition bestMove = null; HashSet <GamePosition> moves = generateMoves(gameLogic, detectiveId, gamePosition); foreach (GamePosition move in moves) { if (detectiveId == gamePosition.Players.Count - 1) { potentialMove = MaxMove(gameLogic, move, depth - 1); } else { potentialMove = MinMove(gameLogic, move, detectiveId + 1, depth - 1); } if (bestMove == null || findValue(potentialMove) < findValue(bestMove)) { bestMove = potentialMove; } } return(bestMove); } }
public static GamePosition MaxMove(GameLogic gameLogic, GamePosition gamePosition, int depth) { int winningPlayerId; if (depth == 0 || gameLogic.winnerExists(gamePosition.Players, out winningPlayerId)) { return(gamePosition); } else { GamePosition potentialMove; GamePosition bestMove = null; HashSet <GamePosition> moves = generateMoves(gameLogic, _mrX, gamePosition); foreach (GamePosition move in moves) { const int firstPlayerId = 1; potentialMove = MinMove(gameLogic, move, firstPlayerId, depth - 1); if (bestMove == null || findValue(potentialMove) > findValue(bestMove)) { bestMove = potentialMove; } } bestMove.Parent = gamePosition; return(bestMove); } }
public async void SelectCharacter(Client client, object[] args) { uint characterId = (uint)(int)args[0]; CharacterData characterData = await CharacterDatabase.GetCharacterData(characterId); Vector3 position = characterData.GetPosition(); float heading = characterData.Heading.HasValue ? characterData.Heading.Value : 0; if (position == null) { GamePosition spawnPoint = ServerUtilities.GetRandomSpawnPoint(); position = spawnPoint.GetPosition(); heading = spawnPoint.GetHeading(); } client.SetData(CharacterData.CHARACTER_DATA_KEY, characterData); PlayerData playerData = client.GetData(PlayerData.PLAYER_DATA_KEY); GroupData highestRankedGroup = await GroupDatabase.GetPlayerHighestRankingGroup(playerData.Id); if (highestRankedGroup == null) { return; } if (characterData == null) { return; } ServerUtilities.SetPlayerNametag(client); ServerUtilities.SwitchPlayerPosition(client, position, heading); }
public HashSet <Node> GetPossibleMoves(int player, GamePosition gamePosition) { Node currentLocation = gamePosition.Players[player].getLocation(); HashSet <Node> possibleLocations = new HashSet <Node>(); HashSet <Node> occupiedLocations = getAllOtherPlayerLocations(gamePosition.Players[player]); HashSet <Node> checkLocations; if (playerHasEnoughTickets(gamePosition.Players[player], TransportType.blackCard)) { checkLocations = currentLocation.getAllEdges(); checkLocations.ExceptWith(occupiedLocations); possibleLocations = new HashSet <Node>(possibleLocations.Union(checkLocations)); } else { foreach (TransportType type in Enum.GetValues(typeof(TransportType))) { if (playerHasEnoughTickets(gamePosition.Players[player], type)) { checkLocations = currentLocation.getEdges(type); checkLocations.ExceptWith(occupiedLocations); possibleLocations = new HashSet <Node>(possibleLocations.Union(checkLocations)); } } } return(possibleLocations); }
public void SetArrow(bool[] array, NodeChoice node, GamePosition gamePosition) { if(gamePosition == GamePosition.Up) { up = upGame; }else{ up = upMove; } if(gamePosition == GamePosition.Down) { down = downGame; }else{ down = downMove; } if(gamePosition == GamePosition.Left) { left = leftGame; }else{ left = leftMove; } if(gamePosition == GamePosition.Right) { right = rightGame; }else{ right = rightMove; } this.upOn = array[0]; this.downOn = array[1]; this.leftOn = array[2]; this.rightOn = array[3]; isGirlOn = true; this.node = node; }
public void dig(GamePosition pos) { if (!isServer) { return; } MapCoords mapCoords = pos.toMapCoords(); Tile tile = mapData.getTile(mapCoords); if (tile.GetType().Equals(typeof(Wall))) { spawnManager.SpawnItemFromTile(new RockItem(), 1, mapCoords.toGamePosition()); spawnManager.SpawnItemFromTile(new DirtItem(), 1, mapCoords.toGamePosition()); if (Random.Range(1, 100) <= 25) { spawnManager.SpawnItemFromTile(new GrubItem(), 1, mapCoords.toGamePosition()); } if (Random.Range(1, 100) <= 50) { spawnManager.SpawnItemFromTile(new WormItem(), 1, mapCoords.toGamePosition()); } } RpcDig(pos.toStruct()); }
private void MoveOutOfNest(GamePosition gamePosition, IPiece piece) { gamePosition.Position = piece.StartPosition; context.GamePositions.Update(gamePosition); piece.Position = piece.StartPosition; }
private static bool DoSmallestSearch(ulong guid) { if (ObjectManager.ShouldDefend) { return(true); } GamePosition.Findpos(Memory.WindowHandle); int xOffset = -40; int yOffset = -40; while (!Memory.ReadObject(Memory.BaseAddress + (uint)Pointers.Globals.MouseOverGUID, typeof(ulong)).Equals(guid)) { MoveMouse(GamePosition.GetCenterX + xOffset, GamePosition.GetCenterY + yOffset); Thread.Sleep(10); if (Memory.ReadObject(Memory.BaseAddress + (uint)Pointers.Globals.MouseOverGUID, typeof(ulong)).Equals(guid)) { break; } xOffset = xOffset + 10; if (xOffset > 50) { yOffset = yOffset + 10; xOffset = -40; if (yOffset > 50) { break; } } } if (Memory.ReadObject(Memory.BaseAddress + (uint)Pointers.Globals.MouseOverGUID, typeof(ulong)).Equals(guid)) { return(true); } return(false); }
private void MoveToGoal(GamePosition gamePosition, IPiece piece) { gamePosition.Position = 100; context.GamePositions.Update(gamePosition); piece.Position = 100; }
public string AddAlias([FromQuery] string Game, [FromQuery] string Position, [FromQuery] string Alias) { Setup(); using (var db = new LiteDatabase(@"/pantherttv/channelsettings.db")) { var coll = db.GetCollection <ChannelQueueSettings>("queuesettings"); if (settings.Games.FirstOrDefault(g => g.Name == Game) is GameSettings newGame) { if (newGame.Positions.FirstOrDefault(p => p.PositionName == Position) is GamePosition p) { if (p.Aliases.FirstOrDefault(p => p == Alias) is string a) { return(string.Format("{0} is already an alias for {1}!", Alias, Position)); } else { p.Aliases.Add(Alias); } } else { GamePosition gp = new GamePosition(Position); gp.Aliases.Add(Alias); newGame.Positions.Add(gp); coll.Update(settings); } return(string.Format("{0} added as an alias to {1} for this channel!", Alias, Position)); } else { return(string.Format("{0} isn't in this channel's list of supported games yet.", Game)); } } }
private void BoardView_AskForUndo(object sender, EventArgs e) { if (PlayerToMove.IsThinking) { return; } if (GamePosition.GameFinished) { return; } int HowManyHalfMoves = (PlayerWaiting is EnginePlayer) ? 2 : 1; for (int i = 0; i < HowManyHalfMoves; i++) { int?MoveToUndo = GamePosition.LastMove; if (MoveToUndo == null) { //No moves handler return; } GamePosition.UnMake(); BoardView.UndoMove((int)MoveToUndo); } int WhiteMaterialAdvantage = CountMaterial(); BoardView.SetMaterial(WhiteMaterialAdvantage, -WhiteMaterialAdvantage); }
public void SpawnPlayerDroppedItem(Item item, int quantity, MoleController playerController) { GamePosition spawnPosition = playerController.gamePos.add(DirectionUtil.getDirectionUnitVector(playerController.facing) * Player.DROP_DISTANCE); spawnPosition.descend(-0.5f); SpawnItem(item, quantity, spawnPosition); }
private int CornerTitels(GamePosition f) { int count = 0; if ((f.tabel[2] == 3 || f.tabel[7] == 8) && f.tabel[3] != 4) { count += 2; } if (f.tabel[7] == 8 && f.tabel[3] != 4) { count += 2; } if ((f.tabel[1] == 2 || f.tabel[5] == 6) && f.tabel[0] != 1) { count += 2; } if (f.tabel[5] == 6 && f.tabel[0] != 1) { count += 2; } if ((f.tabel[8] == 9 || f.tabel[13] == 14) && f.tabel[12] != 13) { count += 2; } if (f.tabel[13] == 14 && f.tabel[12] != 13) { count += 2; } return(count); }
private void tryPlaceDirt() { Vector2 placeOffset = getActionOffset(); GamePosition placeSpot = gamePos.addWorld(placeOffset); CmdPlace(placeSpot.toStruct()); }
private void tryDig() { Vector2 digOffset = getActionOffset(); GamePosition digSpot = gamePos.addWorld(digOffset); CmdDig(digSpot.toStruct()); }
private int LastMove(GamePosition f) { if (f.tabel[numberOfBlocks - 1] == numberOfBlocks - 1 || f.tabel[numberOfBlocks - 1] == numberOfBlocks - numberOfBlockInLine) { return(0); } return(2); }
private void courtRoundsPanel_Leave(object sender, EventArgs e) { if (currentHoveredGamePosition != null) { courtRoundsPaintable.Invalidate(RectangleFToRectangle(currentHoveredGameRectangle)); currentHoveredGamePosition = null; currentHoveredGameRectangle = new RectangleF(); } }
public static HashSet<GamePosition> generateMoves(GameLogic gameLogic, int playerID, GamePosition gamePosition) { HashSet<Node> moves = gameLogic.GetPossibleMoves(playerID, gamePosition); HashSet<GamePosition> possibleMoves = new HashSet<GamePosition>(); foreach(Node move in moves){ possibleMoves.Add(gameLogic.ApplyMove(playerID, move, gamePosition)); } return possibleMoves; }
public Tile getTileFromGamePosition(GamePosition pos) { MapCoords coords = pos.toMapCoords(); if (mapData == null) { return(new Wall(ConnectableVariant.All_Way)); } return(mapData.getTile(coords)); }
public static int findValue(GamePosition game) { int totalValue = 0; foreach(Player player in game.Players.Values){ if(!(player is MrX)){ totalValue += calculateValue(game, player); } } return totalValue; }
private int ManhDist(GamePosition f) { int dist = 0; for (int i = 0; i < numberOfBlocks; i++) { dist += ManhDistMatrix(f.tabel[i] - 1, i); } return(dist); }
public static Pos ToPos(this GamePosition pos) { return(new Pos() { X = pos.X, Y = pos.Y, Value = pos.Value, Id = pos.Value }); }
public List <int> AStar() { long after = 0; long before = GC.GetTotalMemory(true); //для тестирования GamePosition root = new GamePosition(TabelGame, new List <GamePosition>(), -1); PriorityQueue <GamePosition, int> priorityQueue = new PriorityQueue <GamePosition, int>(); priorityQueue.Enqueue(root, 0); GamePosition current = root; List <GamePosition> neighbors; Dictionary <List <int>, int> cost = new Dictionary <List <int>, int>(new ListComparer()) { [root.tabel] = 0 }; int g; int prior; while (!priorityQueue.Empty()) { current = priorityQueue.Dequeue(); if (IsGameOver(current.tabel)) { after = GC.GetTotalMemory(true); // для тестирования priorityQueue.Clear(); } else { neighbors = GenerateNeighbords(current); foreach (var neighbor in neighbors) { g = cost[current.tabel] + ChooseAlgoritm; if (!cost.ContainsKey(neighbor.tabel) || (g < cost[neighbor.tabel])) { cost[neighbor.tabel] = g; prior = g + H(neighbor); priorityQueue.Enqueue(neighbor, prior); } } } } List <int> resultIndex = new List <int>(); GamePosition f = current; while (f.parent.Count != 0) { resultIndex.Add(f.index); f = f.parent[0]; } Test.len = cost.Count(); Test.memory = (after - before) / (1024 * 1024); cost.Clear(); resultIndex.Reverse(); return(resultIndex); }
public EvaluationData( GamePosition position, int depth, int bestLeft, int bestRight) { Position = position; Depth = depth; BestLeft = bestLeft; BestRight = bestRight; }
private static bool IsExists(List <GamePosition> list, GamePosition pos) { foreach (var obj in list) { if (obj.UserId.IsNotNullOrEmpty() && obj.UserId.GetId() == pos.UserId.GetId() && obj.Index != pos.Index) { return(true); } } return(false); }
public HashSet <GamePosition> generateMoves(int playerID, GamePosition gamePosition) { HashSet <Node> moves = GameLogic.GetPossibleMoves(playerID); HashSet <GamePosition> possibleMoves = new HashSet <GamePosition>(); foreach (Node move in moves) { possibleMoves.Add(GameLogic.ApplyMove(playerID, move, gamePosition)); } return(possibleMoves); }
public Atom CreateItem(string type, GamePosition gamePosition) { var tile = type switch { "katana" => new ColouredChar(')', Color.Blue), _ => new ColouredChar('?') }; return(new Atom(type, tile, gamePosition)); } }
public void SpawnItemFromTile(Item item, int quantity, GamePosition position) { GameObject itemGo = GameObject.Instantiate(itemPrefab); ItemEntity ie = itemGo.GetComponent <ItemEntity> (); ie.gamePos = new GamePosition(position.planePosition + Random.insideUnitCircle * RANDOM_SPAWN_AMPLITUDE, position.depth - 0.5f); ie.setIdentity(item); ie.syncPos = ie.gamePos.toStruct(); ie.setQuantity(quantity); NetworkServer.Spawn(itemGo); }
protected void TeleportPlayersIn() { SavePlayersPosition(); for (int i = 0; i < GameModeData.CurrentPlayers.Count; i++) { Client player = GameModeData.CurrentPlayers[i]; GamePosition randomSpawn = GetRandomSpawnPosition(); ServerUtilities.SpawnPlayer(player, randomSpawn); } }
private int CountBlocksIsOutOfPlace(GamePosition f) { count = 0; for (int i = 0; i < f.tabel.Count; i++) { if (f.tabel[i] != i + 1) { count++; } } return(count); }
GamePosition IGameRunner.Step(GamePosition currentPosition, GameAction gameAction) { Contract.Requires<ArgumentNullException>(currentPosition != null); Contract.Requires<ArgumentNullException>(gameAction != null); Contract.Ensures(Contract.Result<GamePosition>() != null); Contract.Ensures(Contract.Result<GamePosition>().FirstTeamPosition != null); Contract.Ensures(Contract.Result<GamePosition>().FirstTeamPosition.Count() == currentPosition.FirstTeamPosition.Count()); Contract.Ensures(Contract.Result<GamePosition>().SecondTeamPosition != null); Contract.Ensures(Contract.Result<GamePosition>().SecondTeamPosition.Count() == currentPosition.SecondTeamPosition.Count()); throw new InvalidOperationException(); }
public static GamePosition ApplyMove(int player, Node move, GamePosition gamePosition) { GamePosition potentialResult = gamePosition; HashSet<TransportType> possibleConnection = getPossibleConnectionTypes(potentialResult.Players[player].getLocation(), move); foreach (TransportType type in possibleConnection) { if (playerHasEnoughTickets(potentialResult.Players[player], type)){ potentialResult.Players[player].move(move, type); break; } } return potentialResult; }
public GamePosition ApplyMove(int player, Node move, GamePosition gamePosition) { int initialPlayerLocation = gamePosition.Players [player].Location.Id; //Debug.Log ("initial plaeyr location: " + initialPlayerLocation); GamePosition potentialResult = new GamePosition (gamePosition.Players); HashSet<TransportType> possibleConnection = getPossibleConnectionTypes(potentialResult.Players[player].getLocation(), move); foreach (TransportType type in possibleConnection) { if (playerHasEnoughTickets(potentialResult.Players[player], type)){ potentialResult.Players[player].move(move, type); break; } } //Debug.Log ("moved player location: " + potentialResult.Players[player].Location.Id); return potentialResult; }
public GamePosition MaxMove(GamePosition gamePosition, int depth) { int winningPlayerId; if(depth == 0 || GameLogic.checkWin(gamePosition.Players, out winningPlayerId)){ return gamePosition; } else { GamePosition potentialMove; GamePosition bestMove = null; HashSet<GamePosition> moves = generateMoves(_mrX, gamePosition); foreach(GamePosition move in moves){ const int firstPlayerId = 1; potentialMove = MinMove(move, firstPlayerId, depth - 1); if(bestMove == null || findValue(potentialMove) > findValue(bestMove)){ bestMove = potentialMove; } } return bestMove; } }
public static TrianglePosition GetPosition(int colorsCount, GamePosition position) { var size = GetMaxTriangleSize(colorsCount); switch (position) { case GamePosition.Top: return new TrianglePosition(size - 1, 0, size); case GamePosition.CenterLeft: return new TrianglePosition(size / 2, 0, size); case GamePosition.CenterRight: return new TrianglePosition(size / 2 - 1, size / 2, size); case GamePosition.BottomLeft: return new TrianglePosition(0, 0, size); case GamePosition.BottomRight: return new TrianglePosition(0, size - 1, size); case GamePosition.BottomCenter: return new TrianglePosition(0, size / 2, size); default: throw new ArgumentOutOfRangeException(nameof(position), position, null); } }
/** * Uses a breadth-first-search to calculate the distance between a given Detective and Mr X. * Only considers the absolute distance between the Detective and Mr. X. Ticket amounts are * not accounted for. */ public static int calculateValue(GamePosition game, Player player) { int mrXId = 0; var nodes = new HashSet<Node>(game.Board.Values); foreach(Node node in nodes){ node.Color = Color.white; node.Value = Int32.MaxValue; node.Parent = null; } player.getLocation().Color = Color.gray; player.getLocation().Value = 0; player.getLocation().Parent = null; int MAX_NUMBER_OF_NODES = 200; HeapPriorityQueue<Node> pq = new HeapPriorityQueue<Node>(MAX_NUMBER_OF_NODES); Node playerLocation = player.getLocation(); pq.Enqueue(playerLocation, playerLocation.Value); while(pq.First != null){ Node u = pq.Dequeue(); foreach(Node v in u.getAllEdges()){ if(v.Color == Color.white){ v.Color = Color.gray; v.Value = u.Value + 1; v.Parent = u; if(v == game.Players[mrXId].getLocation()){ return v.Value; } pq.Enqueue(v, v.Value); } } u.Color = Color.black; } throw new Exception ("calculate value error!!!!!!!"); //Not all code paths return a value, should the following line be here? return MAX_NUMBER_OF_NODES; }
public GameLogic(TextAsset nodeConnections, params Player[] players) { Debug.Log ("game logic ctor"); GameBoard = new GamePosition(players[0], players[1], players[2], players[3]); BuildMap(nodeConnections); }
public static GamePosition minMax(GameLogic gameLogic, int mrX, int depth) { _mrX = mrX; Dictionary<int, Player> players = gameLogic.GameBoard.Players; _detectives = new HashSet<int>(players.Keys); _detectives.Remove(_mrX); //don't change the gameposition of the game being played - modify a copy GamePosition copyOfGamePosition = new GamePosition (gameLogic.GameBoard.Players); GamePosition bestMove = MaxMove(gameLogic, copyOfGamePosition, depth * players.Count + 1); List<int> moves = new List<int> (); GamePosition nextMove = bestMove; while (nextMove.Parent != null) { moves.Add(nextMove.Players[0].Location.Id); nextMove = nextMove.Parent; } StringBuilder movesString = new StringBuilder(); foreach (var move in moves) { movesString.Append(move + " "); } Debug.Log ("moves: " + movesString); Debug.Log ("best move: " + nextMove.Players[0].Location.Id); return nextMove; }
public static GamePosition MinMove(GameLogic gameLogic, GamePosition gamePosition, int detectiveId, int depth) { int winningPlayerId; if(depth == 0 || gameLogic.winnerExists(gamePosition.Players, out winningPlayerId)){ return gamePosition; } else { GamePosition potentialMove; GamePosition bestMove = null; HashSet<GamePosition> moves = generateMoves(gameLogic, detectiveId, gamePosition); foreach(GamePosition move in moves){ if(detectiveId == gamePosition.Players.Count - 1){ potentialMove = MaxMove(gameLogic, move, depth - 1); } else{ potentialMove = MinMove(gameLogic, move, detectiveId+1, depth - 1); } if(bestMove == null || findValue(potentialMove) < findValue(bestMove)){ bestMove = potentialMove; } } return bestMove; } }
public HashSet<Node> GetPossibleMoves(int player, GamePosition gamePosition) { Node currentLocation = gamePosition.Players[player].getLocation(); HashSet<Node> possibleLocations = new HashSet<Node>(); HashSet<Node> occupiedLocations = getAllOtherPlayerLocations(gamePosition.Players[player]); HashSet<Node> checkLocations; if(playerHasEnoughTickets(gamePosition.Players[player], TransportType.blackCard)){ checkLocations = currentLocation.getAllEdges(); checkLocations.ExceptWith(occupiedLocations); possibleLocations = new HashSet<Node>(possibleLocations.Union(checkLocations)); } else { foreach(TransportType type in Enum.GetValues(typeof(TransportType))){ if(playerHasEnoughTickets(gamePosition.Players[player], type)){ checkLocations = currentLocation.getEdges(type); checkLocations.ExceptWith(occupiedLocations); possibleLocations = new HashSet<Node>(possibleLocations.Union(checkLocations)); } } } return possibleLocations; }
public GamePosition minMax(GamePosition gamePosition, int mrX, int depth) { _mrX = mrX; Dictionary<int, Player> players = gamePosition.Players; _detectives = new HashSet<int>(players.Keys); _detectives.Remove(_mrX); //don't change the gameposition of the game being played - modify a copy GamePosition copyOfGamePosition = new GamePosition { Board = new Dictionary<int, Node>(gamePosition.Board), Players = new Dictionary<int, Player>(gamePosition.Players) }; return MaxMove(gamePosition, depth * players.Count); }