private async Task <long> CreateScoringAsync( Project project, ScoringInfo scoringInfo) { var contractAddress = await _scoringsRegistryContractClient.GetScoringAddressAsync(project.ExternalId); var areaScorings = await _scoringsRegistryContractClient.GetRequiredExpertsCountsAsync(project.ExternalId); var offers = await CreateOffersAsync(scoringInfo.Offers); var scoring = new Scoring( project.Id, contractAddress, _clock.UtcNow, scoringInfo.AcceptingDeadline, scoringInfo.ScoringDeadline, areaScorings.Select(x => new AreaScoring { AreaId = x.Area, ExpertsCount = x.Count }).ToArray(), offers); _scoringRepository.Add(scoring); await _scoringRepository.SaveChangesAsync(); return(scoring.Id); }
public float GetScore(ScoringInfo a_scoringInfo) { // Set up all the input nodes to have the right values List <InputNode> workList = new List <InputNode>(); for (int x = 0; x < calculationCanvas.nodes.Count; x++) { Node node = calculationCanvas.nodes[x]; if (node.GetID == "inputNode") { workList.Add((InputNode)node); } } foreach (InputNode node in workList) { Unit player = a_scoringInfo.Player; switch (node.inputType) { case InputType.player: switch (node.playerValue) { case PlayerValue.health: node.Value = player.CurrentHealth; // Set to players health break; case PlayerValue.maxHealth: node.Value = player.MaxHealth; // Set to players max health break; default: break; } break; case InputType.agent: switch (node.agentValue) { case AgentValue.damage: node.Value = agent.Damage; // Set to agents damage break; case AgentValue.movement: node.Value = agent.CanMove ? agent.MoveRange : 0; // Set to agents movement break; default: break; } break; case InputType.world: switch (node.worldValue) { case WorldValue.movesToAttackRange: node.Value = a_scoringInfo.MovesToAttackRange; // Set to moves to attack range break; default: break; } break; default: break; } } calculationCanvas.Calculate(); return(calculationCanvas.Output); }
protected virtual IEnumerator DoTurn(GridManager a_grid) { AI_Action bestAction = null; int playerToAttack = 0; float bestScore = int.MinValue; List <Hex> path = null; players[0] = Manager.instance.PlayerController.EarthUnit; players[1] = Manager.instance.PlayerController.LightningUnit; ScoringInfo[] scoringInfo = new ScoringInfo[2]; scoringInfo[0] = (players[0] == null || players[0].IsDead) ? null : new ScoringInfo(a_grid, this, players[0]); scoringInfo[1] = (players[1] == null || players[1].IsDead) ? null : new ScoringInfo(a_grid, this, players[1]); foreach (AI_Action action in actions) { for (int i = 0; i < 2; i++) { if (scoringInfo[i] == null) { continue; } float score = action.GetScore(scoringInfo[i]); if (scoringInfo[i].Path != null) { if (score > bestScore) { bestAction = action; playerToAttack = i; bestScore = score; path = scoringInfo[i].Path; } } } } if (bestAction == null) { Debug.Log("No valid actions found", gameObject); turnComplete = true; yield break; } // Remove the path that is out of the movement range if (path.Count > MoveRange) { path.RemoveRange(MoveRange, path.Count - MoveRange); } // Path find and wait for it to finish isPerformingAction = true; finishedWalking = FinishedAction; StartCoroutine(Walk(path)); yield return(new WaitUntil(() => isPerformingAction == false)); // Attack the player, checking if it is in range && if we have a clear shot if (HexUtility.Distance(currentTile, players[playerToAttack].CurrentTile) <= attackRange && HasClearShot(players[playerToAttack])) { isPerformingAction = true; BasicAttack(new Hex[] { players[playerToAttack].CurrentTile }, null, FinishedAction); yield return(new WaitUntil(() => isPerformingAction == false)); } turnComplete = true; yield break; }
public float GetScore(ScoringInfo a_scoringInfo) { return(scorer.GetScore(a_scoringInfo)); }