/// <summary> /// Loop round all AI teams, and select a team appropriate to play the fixture. /// </summary> public void SelectTeamIfPlaying() { FixtureAdapter fa = new FixtureAdapter(); WorldAdapter wa = new WorldAdapter(); TeamAdapter ta = new TeamAdapter(); ManagerAdapter ma = new ManagerAdapter(); List <Fixture> AllFixtures = fa.GetFixtures(wa.CurrentDate); int TESTf = 0; foreach (Fixture f in AllFixtures) { TESTf++; Debug.Print("Fixture " + f.ToString()); for (int t = 0; t <= 1; t++) { Team ThisTeam = ta.GetTeam(f.TeamIDs[t]); Manager M = ma.GetManager(ThisTeam.ManagerID); if (!M.Human) { Team Opposition = ta.GetTeam(f.TeamIDs[1 - t]); PlayerAdapter pa = new PlayerAdapter(); int[,] PlayerGridPositions = new int[5, 8]; // TODO: Maybe not hard code these... for (int x = 0; x <= PlayerGridPositions.GetUpperBound(0); x++) { for (int y = 0; y <= PlayerGridPositions.GetUpperBound(1); y++) { PlayerGridPositions[x, y] = -1; } } Formation TeamFormation = new FormationAdapter().GetFormation(ThisTeam.CurrentFormation); List <AvailablePlayer> avail = GetEligiblePlayers(ThisTeam, f); foreach (Point2 point in TeamFormation.Points) { AvailablePlayer SelPlayer = FindBestPlayerForPosition(point, avail); if (SelPlayer == null) { throw new Exception("Unable to find a player for this position"); } PlayerGridPositions[point.X, point.Y] = SelPlayer.PlayerID; avail.Remove(SelPlayer); } ta.SavePlayerFormation(ThisTeam.UniqueID, TeamFormation.UniqueID, PlayerGridPositions); } } } }
private void SetupControl() { imgPitch.ImageSource = ImageResources.GetImage(ImageResourceList.Pitch); // Paging control for formations FormationAdapter fa = new FormationAdapter(); foreach (Formation f in fa.GetFormations()) { FormationPaging.Items.Add(new PagingItem() { ID = f.UniqueID, Name = f.Name }); } // Create empty circles inside the grid // Set the PlayerGridPositions to blanks for (int x = 0; x < GRIDWIDTH; x++) { for (int y = 0; y < GRIDHEIGHT; y++) { // --- Marker symbol --- Markers[x, y] = GraphicUtils.Shirt(); Markers[x, y].VerticalAlignment = VerticalAlignment.Center; Markers[x, y].HorizontalAlignment = HorizontalAlignment.Center; Markers[x, y].AllowDrop = true; Markers[x, y].Drop += new DragEventHandler(Marker_Drop); Markers[x, y].Tag = x.ToString() + "," + y.ToString(); Grid.SetColumn(Markers[x, y], x + 1); Grid.SetRow(Markers[x, y], 8 - y); grdPitch.Children.Add(Markers[x, y]); // --- Text --- MarkerText[x, y] = new TextBlock(); MarkerText[x, y].Text = ""; MarkerText[x, y].Visibility = Visibility.Hidden; MarkerText[x, y].Foreground = Brushes.White; MarkerText[x, y].FontSize = 12; MarkerText[x, y].FontFamily = new FontFamily("Roboto Black"); MarkerText[x, y].VerticalAlignment = VerticalAlignment.Center; MarkerText[x, y].HorizontalAlignment = HorizontalAlignment.Center; Grid.SetColumn(MarkerText[x, y], x + 1); Grid.SetRow(MarkerText[x, y], 8 - y); grdPitch.Children.Add(MarkerText[x, y]); PlayerGridPositions[x, y] = -1; } } }
public void SetupFormationTemplate(int FormationID) { CurrentFormationID = FormationID; for (int x = 0; x < GRIDWIDTH; x++) { for (int y = 0; y < GRIDHEIGHT; y++) { SetMarkerTemplate(x, y, false); MarkerText[x, y].Visibility = Visibility.Hidden; PlayerGridPositions[x, y] = -1; } } FormationAdapter fa = new FormationAdapter(); List <Point2> points = fa.GetFormation(FormationID).Points; foreach (Point2 p in points) { SetMarkerTemplate((int)p.X, (int)p.Y, true); } }
private AvailablePlayer FindBestPlayerForPosition(Point2 GridPos, List <AvailablePlayer> avail) { PlayerAdapter pa = new PlayerAdapter(); FormationAdapter fa = new FormationAdapter(); SuitablePlayerInfo suit = fa.SuitablePlayerPositions(GridPos); AvailablePlayer best = null; foreach (PlayerPosition pos in suit.Positions) { foreach (PlayerPositionSide side in suit.Sides) { best = (from ap in avail where ap.Side == side && ap.Pos == pos select ap).FirstOrDefault(); if (best != null) { break; } } if (best != null) { break; } } if (best == null) { best = (from ap in avail orderby ap.Rating descending select ap).FirstOrDefault(); } return(best); }