public void Draw(SpriteBatch spriteBatch) { for (int i = 0; i < FullMap.Count(); i++) { for (int j = 0; j < FullMap[i].Count(); j++) { int currentNum = FullMap[i][j]; switch (currentNum) { case 0: cropWall = new Rectangle(0, 0, 50, 50); break; case 1: cropWall = new Rectangle(50, 0, 50, 50); break; case 2: cropWall = new Rectangle(100, 0, 50, 50); break; } currentCoord.X = (float)(j * 50); currentCoord.Y = (float)(i * 50); spriteBatch.Draw(MapManager.Instance.Terrain, currentCoord, cropWall, Color.White); } } }
protected async Task ShowMap() { Position center; if (viewModel.Items.Count == 0) { var current = await CrossGeolocator.Current.GetPositionAsync(2000); center = new Position(current.Latitude, current.Longitude); } else { var first = viewModel.Items.FirstOrDefault(); center = new Position(first.Latitude, first.Longitude); } FullMap.MoveToRegion(MapSpan.FromCenterAndRadius(center, Distance.FromMeters(100))); FullMap.Pins.Clear(); foreach (var item in viewModel.Items) { var pin = new Pin { Type = PinType.SearchResult, Position = new Position(item.Latitude, item.Longitude), Label = item.Text, Address = item.Description }; FullMap.Pins.Add(pin); } Console.WriteLine(viewModel.Items.Count()); }
/// <summary> /// Parses a list of the opponent's moves every round. /// Clears it at the start, so only the moves of this round are stored. /// </summary> /// <param name="moveInput"></param> public void ReadOpponentMoves(string[] moveInput) { OpponentMoves.Clear(); for (var i = 1; i < moveInput.Length; i++) { try { Move move; if (moveInput[i + 1].Equals("place_armies")) { var region = VisibleMap.GetRegion(int.Parse(moveInput[i + 2])); var playerName = moveInput[i]; var armies = int.Parse(moveInput[i + 3]); move = new PlaceArmiesMove(playerName, region, armies); i += 3; } else if (moveInput[i + 1].Equals("attack/transfer")) { var fromRegion = VisibleMap.GetRegion(int.Parse(moveInput[i + 2])); if (fromRegion == null) { //might happen if the region isn't visible fromRegion = FullMap.GetRegion(int.Parse(moveInput[i + 2])); } var toRegion = VisibleMap.GetRegion(int.Parse(moveInput[i + 3])); if (toRegion == null) { //might happen if the region isn't visible toRegion = FullMap.GetRegion(int.Parse(moveInput[i + 3])); } var playerName = moveInput[i]; var armies = int.Parse(moveInput[i + 4]); move = new AttackTransferMove(playerName, fromRegion, toRegion, armies); i += 4; } else { //never happens continue; } OpponentMoves.Add(move); } catch (Exception e) { Console.Error.WriteLine("Unable to parse Opponent moves " + e.Message); } } }
/// <summary> /// Regions from wich a player is able to pick his preferred starting region. /// </summary> /// <param name="input"></param> public void SetPickableStartingRegions(string[] input) { PickableStartingRegions = new List <Region>(); for (var i = 2; i < input.Length; i++) { try { var regionId = int.Parse(input[i]); var pickableRegion = FullMap.GetRegion(regionId); PickableStartingRegions.Add(pickableRegion); } catch (Exception e) { Console.Error.WriteLine("Unable to parse pickable regions " + e.Message); } } }
/// <summary> /// Visible regions are given to the bot with player and armies info. /// </summary> /// <param name="mapInput"></param> public void UpdateMap(string[] mapInput) { VisibleMap = FullMap.GetMapCopy(); for (var i = 1; i < mapInput.Length; i++) { try { var region = VisibleMap.GetRegion(int.Parse(mapInput[i])); var playerName = mapInput[i + 1]; var armies = int.Parse(mapInput[i + 2]); region.PlayerName = playerName; region.Armies = armies; i += 2; } catch (Exception e) { Console.Error.WriteLine("Unable to parse Map Update " + e.Message); } } var unknownRegions = new List <Region>(); //remove regions which are unknown. foreach (var region in VisibleMap.Regions) { if (region.PlayerName.Equals("unknown")) { unknownRegions.Add(region); } } foreach (var unknownRegion in unknownRegions) { VisibleMap.Regions.Remove(unknownRegion); } }
/// <summary> /// Initial map is given to the bot with all the information except for player and armies info. /// </summary> /// <param name="mapInput"></param> public void SetupMap(string[] mapInput) { int i, regionId, superRegionId, wastelandId, reward; if (mapInput[1].Equals("super_regions")) { for (i = 2; i < mapInput.Length; i++) { try { superRegionId = int.Parse(mapInput[i]); i++; reward = int.Parse(mapInput[i]); FullMap.Add(new SuperRegion(superRegionId, reward)); } catch (Exception e) { Console.Error.WriteLine("Unable to parse SuperRegions " + e.Message); } } } else if (mapInput[1].Equals("regions")) { for (i = 2; i < mapInput.Length; i++) { try { regionId = int.Parse(mapInput[i]); i++; superRegionId = int.Parse(mapInput[i]); var superRegion = FullMap.GetSuperRegion(superRegionId); FullMap.Add(new Region(regionId, superRegion)); } catch (Exception e) { Console.Error.WriteLine("Unable to parse Regions " + e.Message); } } } else if (mapInput[1].Equals("neighbors")) { for (i = 2; i < mapInput.Length; i++) { try { var region = FullMap.GetRegion(int.Parse(mapInput[i])); i++; var neighborIds = mapInput[i].Split(','); for (var j = 0; j < neighborIds.Length; j++) { var neighbor = FullMap.GetRegion(int.Parse(neighborIds[j])); region.AddNeighbor(neighbor); } } catch (Exception e) { Console.Error.WriteLine("Unable to parse Neighbors " + e.Message); } } } else if (mapInput[1].Equals("wastelands")) { Wastelands = new List <Region>(); for (i = 2; i < mapInput.Length; i++) { try { wastelandId = int.Parse(mapInput[i]); Wastelands.Add(FullMap.GetRegion(wastelandId)); } catch (Exception e) { Console.Error.WriteLine("Unable to parse wastelands " + e.Message); } } } }
void Setup_Frame2Full() { //if (FrameMap.Rank == 0) // Debugger.Launch(); //csMPI.Raw.Barrier(csMPI.Raw._COMM.WORLD); //FrameMap.GridDat.Cells.NoOfLocalUpdatedCells int L = FrameMap.LocalLength; Frame2Full_Lookup = new int[L]; Basis[] BasisS = FullMap.BasisS.ToArray(); XDGBasis[] XBasisS = new XDGBasis[BasisS.Length]; for (int i = 0; i < BasisS.Length; i++) { XBasisS[i] = BasisS[i] as XDGBasis; } var GridDat = this.FullMap.GridDat; Frame2Full_Lookup = new int[L]; Frame2Full_Lookup.SetAll(int.MinValue); int Jup = FrameMap.GridDat.iLogicalCells.NoOfLocalUpdatedCells; int Jtot = FrameMap.GridDat.iLogicalCells.Count; int G = BasisS.Length; for (int j = 0; j < Jup; j++) // loop over all cells ... { int NoOfSpc = m_Regions.GetNoOfSpecies(j); int iSpc = m_Regions.GetSpeciesIndex(m_spcId, j); for (int g = 0; g < G; g++) // loop over all basises { Basis b = BasisS[g]; XDGBasis xb = XBasisS[g]; bool b_is_XDGbasis = (xb != null); int n0, N; if (b_is_XDGbasis) { if (iSpc < 0) { n0 = int.MaxValue; N = int.MinValue; } else { N = xb.DOFperSpeciesPerCell; n0 = N * iSpc; } } else { n0 = 0; N = b.GetLength(j); } if (N >= 0) { int iFull = (int)FullMap.GlobalUniqueCoordinateIndex(g, j, n0); int iLoc = FrameMap.LocalUniqueCoordinateIndex(g, j, 0); for (int n = 0; n < N; n++) { Frame2Full_Lookup[iLoc + n] = iFull + n; Debug.Assert(Frame2Full_Lookup[iLoc + n] < 0 || FullMap.IsInLocalRange(Frame2Full_Lookup[iLoc + n])); } } } } #if DEBUG var _Frame2Full_Lookup = new int[L]; for (int iLoc = 0; iLoc < L; iLoc++) // loop over all indices of the frame... { int j, g, n; FrameMap.LocalFieldCoordinateIndex(iLoc, out g, out j, out n); int NoOfSpc = m_Regions.GetNoOfSpecies(j); Basis b = BasisS[g]; XDGBasis xb = XBasisS[g]; bool b_is_XDGbasis = (xb != null); int iSpc = m_Regions.GetSpeciesIndex(m_spcId, j); if (b_is_XDGbasis) { if (iSpc < 0) { _Frame2Full_Lookup[iLoc] = int.MinValue; } else { int Nsep = xb.DOFperSpeciesPerCell; _Frame2Full_Lookup[iLoc] = (int)(FullMap.GlobalUniqueCoordinateIndex(g, j, iSpc * Nsep + n)); } } else { _Frame2Full_Lookup[iLoc] = (int)(FullMap.GlobalUniqueCoordinateIndex(g, j, n)); } Debug.Assert(_Frame2Full_Lookup[iLoc] == Frame2Full_Lookup[iLoc]); } for (int l = 0; l < L; l++) { Debug.Assert(Frame2Full_Lookup[l] < 0 || FullMap.IsInLocalRange(Frame2Full_Lookup[l])); } #endif /* * if (m_supportExternal) { * int[] PeerProcess = GridDat.Parallel.ProcessesToReceiveFrom; * int TT = PeerProcess.Length; * int DOFperCell = FrameMap.MaxTotalNoOfCoordinatesPerCell; * * ExtRangeStart = new int[TT]; * ExtRangeLen = new int[TT]; * ExtRangeTrafo = new int[TT][]; * * for(int tt = 0; tt < TT; tt++) { * int otherRank = PeerProcess[tt]; * int jFristCell = GridDat.Parallel.m_RcvCommListsInsertIndex[otherRank]; * int Jrank = GridDat.Parallel.m_RcvCommListsNoOfItems[otherRank]; * * * int offset = (int)(FrameMap.GlobalUniqueCoordinateIndex(0, jFristCell, 0)); * ExtRangeStart[tt] = offset; * ExtRangeLen[tt] = Jrank*DOFperCell; * * * ExtRangeTrafo[tt] = new int[ExtRangeLen[tt]]; * ExtRangeTrafo[tt].SetAll(int.MinValue); * * for (int j = 0; j < Jrank; j++) { // loop over all external cells that this process receives from 'otherRank' ... * int jCell = j + jFristCell; * Debug.Assert(jCell >= Jup); * Debug.Assert(jCell < Jtot); * ReducedRegionCode rrc; * int NoOfSpc = m_lsTrk.GetNoOfSpecies(jCell, out rrc); * int iSpc = m_lsTrk.GetSpeciesIndexFromId(rrc, m_spcId); * * for (int g = 0; g < G; g++) { // loop over all basises * Basis b = BasisS[g]; * XDGBasis xb = XBasisS[g]; * bool b_is_XDGbasis = (xb != null); * * int n0, N; * if (b_is_XDGbasis) { * if (iSpc < 0) { * n0 = int.MaxValue; * N = int.MinValue; * } else { * N = xb.DOFperSpeciesPerCell; * n0 = N*iSpc; * } * } else { * n0 = 0; * N = b.GetLength(j); * } * * if (N >= 0) { * int iFull = (int)(FullMap.GlobalUniqueCoordinateIndex(g, jCell, n0)); * int iFrame = (int)(FrameMap.GlobalUniqueCoordinateIndex(g, jCell, 0)); * * for (int n = 0; n < N; n++) { * ExtRangeTrafo[tt][iFrame + n - offset] = iFull + n; * } * } * } * } * } * } */ { int NoOfSpc = this.m_Regions.SpeciesIdS.Count; int N_frame = this.FrameMap.MaxTotalNoOfCoordinatesPerCell; var FramBasisS = this.FrameMap.BasisS.ToArray(); var FullBasisS = this.FullMap.BasisS.ToArray(); int[] NBs = FramBasisS.Select(b => b.Length).ToArray(); int[] NBf = FullBasisS.Select(b => b.MaximalLength).ToArray(); Debug.Assert(NBf.Length == NBs.Length); for (int i = 0; i < NBf.Length; i++) { Debug.Assert(NBf[i] % NBs[i] == 0); } bool[] XBasis = FullBasisS.Select(b => b is XDGBasis).ToArray(); this.IndexTrafoWithinCell = new int[NoOfSpc, this.FrameMap.MaxTotalNoOfCoordinatesPerCell]; for (int iSpc = 0; iSpc < NoOfSpc; iSpc++) // loop over all possible species indices { int n_frame = 0; int n_full = 0; for (int ifld = 0; ifld < NBs.Length; ifld++) // loop over all basises in the mapping { if (XBasis[ifld]) { for (int n = 0; n < NBs[ifld]; n++) { this.IndexTrafoWithinCell[iSpc, n_frame + n] = n_full + iSpc * NBs[ifld] + n; } } else { for (int n = 0; n < NBs[ifld]; n++) { this.IndexTrafoWithinCell[iSpc, n_frame + n] = n_full + n; } } n_frame += NBs[ifld]; n_full += NBf[ifld]; } } } }