public override void CollectObservations() { List <GameObject> neighbors = gameState.getNeighbors(x, y, sight); foreach (GameObject neighbor in neighbors) { GameState.HexTypes type = neighbor.GetComponent <Hex>().getType(); AddVectorObs((int)type, 9); GameObject other = neighbor.GetComponent <Hex>().unitInHex; if (other == null) { AddVectorObs(NoUnit, 3); } else if (other.GetComponent <UnitAgent>().team == team) { AddVectorObs(Friendly, 3); } else { AddVectorObs(Enemy, 3); } } Coordinates3D coordDist = Coordinates3D.AddCoordinates( new Coordinates3D(homeX, homeY), new Coordinates3D(-x, -y)); AddVectorObs(Sigmoid(coordDist.x)); AddVectorObs(Sigmoid(coordDist.y)); AddVectorObs(Sigmoid(coordDist.z)); AddVectorObs((Sigmoid(attack) - 0.5f) * 2); }
protected void Move(Coordinates2D newPos) { Hex hex = gameState.GetHex(newPos).GetComponent <Hex>(); if (hex.unitInHex != null) { if (!Fight(this, hex.unitInHex.GetComponent <UnitAgent>())) { return; } } GameState.HexTypes type = hex.getType(); Coordinates3D coordDist = Coordinates3D.AddCoordinates( new Coordinates3D(homeX, homeY), new Coordinates3D(-x, -y)); float dist = Mathf.Abs(coordDist.x) + Mathf.Abs(coordDist.y) + Mathf.Abs(coordDist.z); dist = dist / 2; dist = dist * .05f; dist = (dist - 0.15f) / (dist + 0.85f); AddReward(Mathf.Min(Mathf.Max(-dist, maxMovePenalty), 0)); //Debug.Log(-dist); AddReward(-0.02f); switch (type) { case GameState.HexTypes.Mountain: AddReward(-0.02f); break; case GameState.HexTypes.Water: SetReward(-1f); Dead(); Done(); Debug.Log("In Water!"); break; default: transform.position = hex.transform.position; gameState.GetHex(new Coordinates2D(x, y)).GetComponent <Hex>().unitInHex = null; x = newPos.x; y = newPos.y; hex.unitInHex = gameObject; break; } }
public static Coordinates3D[] getRing(Coordinates3D center, int radius) { int size = radius * 6; Coordinates3D[] ring = new Coordinates3D[size]; Coordinates3D hex = Coordinates3D.AddCoordinates(center, Coordinates3D.MultiplyCoordinates(Hex.NeighborDirections(HexDirections.DOWNLEFT), radius)); int num = 0; for (int i = 0; i < 6; i++) { for (int j = 0; j < radius; j++) { ring [num] = hex; num++; hex = Coordinates3D.AddCoordinates(hex, Hex.NeighborDirections(i)); } } return(ring); }