//protected coords NearestEnergy(GameState gs, RobotState myself) //{ // int dist = 999999999; // coords cd = new coords(); // foreach (Point p in gs.points) // { // if ((p.type == PointType.Energy) && (getDistance(myself.X, myself.Y, p.X, p.Y) < dist) && (p.X != rs.Y) && (p.Y != rs.X) && (rs.isAlive == true) && (rs.id != myself.id) && (friends.Contains(rs.name))) // { // cd.X = p.X; // cd.Y = p.Y; // dist = getDistance(myself.X, myself.Y, p.X, p.Y); // } // } // return cd; //} protected coords getFurtherEnergy(List <string> friends, GameState gs, RobotState myself) { int dist = 0; coords cd = new coords(); foreach (Point p in gs.points) { foreach (RobotState rs in gs.robots) { if ((p.X == rs.Y) && (p.Y == rs.X) && (friends.Contains(rs.name))) { cd.X = p.X; cd.Y = p.Y; dist = getDistance(myself.X, myself.Y, p.X, p.Y); } else { if ((p.type == PointType.Energy) && (getDistance(myself.X, myself.Y, p.X, p.Y) > dist) && (p.X != rs.Y) && (p.Y != rs.X) && (rs.isAlive == true) && (rs.id != myself.id)) { cd.X = p.X; cd.Y = p.Y; dist = getDistance(myself.X, myself.Y, p.X, p.Y); } } } } return(cd); }
IEnumerator move_sprite() { int total_frame = 29; int frame = 0; while (true) { coords locate = pos[frame] as coords; Vector2 size = new Vector2(locate.x, locate.y); Vector2 offset = new Vector2(locate.offsetX, locate.offsetY); _obj.renderer.material.SetTextureScale("_MainTex", size); _obj.renderer.material.SetTextureOffset("_MainTex", offset); yield return(new WaitForSeconds(0.02F)); if (frame < total_frame) { ++frame; } else { frame = 0; } } }
protected coords getNearestHealth(List <string> friends, GameState gs, RobotState myself) { int dist = 999999999; coords cd = new coords(); foreach (Point p in gs.points) { foreach (RobotState rs in gs.robots) { if ((p.X == rs.Y) && (p.Y == rs.X) && (friends.Contains(rs.name))) { cd.X = p.X; cd.Y = p.Y; dist = getDistance(myself.X, myself.Y, p.X, p.Y); } else { if ((p.type == PointType.Health) && (getDistance(myself.X, myself.Y, p.X, p.Y) < dist) && (p.X != rs.Y) && (p.Y != rs.X) && (rs.isAlive == true) && (rs.id != myself.id)) { cd.X = p.X; cd.Y = p.Y; dist = getDistance(myself.X, myself.Y, p.X, p.Y); } } } } //if (dist == 999999999) // cd = NearestEnergy(gs, myself); return(cd); }
public Vector3 PositionFromIdx(coords tileIndex) { return new Vector3 ( BottomLeft.x + cubeSize * (tileIndex.X + 0.5f), BottomLeft.y + cubeSize * (tileIndex.X + 0.5f), 0f); }
// calcula las coordenadas de las casillas adyacentes de una concreta // tiene en cuenta no salirse del margen del mapa private List <coords> calcAdyacentes(int posX, int posZ, box[,] table) { dir up = new dir(0, 1); dir down = new dir(0, -1); dir left = new dir(-1, 0); dir right = new dir(1, 0); dir[] directions = new dir[4]; directions[0] = up; directions[1] = down; directions[2] = left; directions[3] = right; List <coords> adyacentes = new List <coords>(); for (int i = 0; i < 4; i++) { coords aux; int nX = posX + directions[i].x_; int nZ = posZ + directions[i].z_; if (nX >= 0 && nZ >= 0 && nX < table.GetLength(0) && nZ < table.GetLength(1)) { aux = new coords(nX, nZ); adyacentes.Add(aux); } } return(adyacentes); }
//method that check is the number you entered is correct or not //and handles the cases public static void CheckCorrect_Replace(int[,] grid, char input, Button btn, Button[,] array_btn) { int number = input - '0'; //converting the char input into a working number bool correct, modifiability; coords coordinates = new coords(); coordinates = GetCoordinates(btn, array_btn); correct = Checking(coordinates, input.ToString(), array_btn); modifiability = ModifiabilityCheck(coordinates, grid); if (correct && modifiability) { array_btn[coordinates.i, coordinates.j].Text = input.ToString(); grid[coordinates.i, coordinates.j] = number; } if (modifiability == false) { MessageBox.Show("Please select a valid area "); } else { if (!correct) { MessageBox.Show("Number you entered is not correct, try again"); } } }
// Start is called before the first frame update void Start() { rb2d = GetComponent <Rigidbody2D> (); TextAsset coord_data = Resources.Load <TextAsset>("144718_1"); string[] data = coord_data.text.Split(new char[] { '\n' }); //string[] start_pos = data[1].Split(new char[] { ',' }); //coords start_coord = new coords(); //float.TryParse(start_pos[0], out start_coord.x); //float.TryParse(start_pos[1], out start_coord.y); for (int i = 1; i < data.Length - 1; i++) { string[] row = data[i].Split(new char[] { ',' }); coords a = new coords(); float.TryParse(row[0], out a.x); float.TryParse(row[1], out a.y); coords.Add(a); } }
/*движение к ближайшей точке*/ public coords MoveTo(RobotState self, RoundConfig config, coords coords) { /*максимальная дальность перемещения*/ int maxdistance = 10 * config.max_speed * self.speed / config.max_health * self.energy / config.max_energy; coords NewMoveToPoint = new coords(); coords finalcoords = new coords(); coords testcoords = new coords(); int dx = coords.x - self.X; int dy = coords.y - self.Y; bool sw = false; coords sign_cd = new coords(); sign_cd.x = Sign(dx); sign_cd.y = Sign(dy); finalcoords.x = 0; finalcoords.y = 0; if (TakeDistance(self.X, self.Y, coords.x, coords.y) < maxdistance) { finalcoords.x = dx; finalcoords.y = dy; } else { testcoords.x = 0; testcoords.y = 0; while (pifagor(testcoords.x, testcoords.y) <= maxdistance) { if (sw) { testcoords.x += sign_cd.x; if (pifagor(testcoords.x, testcoords.y) > maxdistance) { break; } else { finalcoords.x += sign_cd.x; } } else { testcoords.y += sign_cd.y; if (pifagor(testcoords.x, testcoords.y) > maxdistance) { break; } else { finalcoords.y += sign_cd.y; } } sw = !sw; } } return(finalcoords); }
//method that checks if the number is modifiable or not(if it //was already in the matrix before this) public static bool ModifiabilityCheck(coords coordinates, int [,] matrix) { if (matrix[coordinates.i, coordinates.j] != 0) { return(false); } return(true); }
public static void BackSpaceDel(int[,] matrix, Button btn, Button[,] arr_btn) { coords coordinates = new coords(); coordinates = GetCoordinates(btn, arr_btn); matrix[coordinates.i, coordinates.j] = 0; btn.Text = ""; }
public coords MoveTo(RobotState self, RoundConfig config, coords coords) { int maxdistance = 10 * config.max_speed * self.speed / config.max_health * self.energy / config.max_energy; coords Move = new coords(); coords finalPosition = new coords(); coords tryPosition = new coords(); int DX = coords.x - self.X; int DY = coords.y - self.Y; bool sw = false; coords sign_cd = new coords(); sign_cd.x = Sign(DX); sign_cd.y = Sign(DY); finalPosition.x = 0; finalPosition.y = 0; if (TakeDistance(self.X, self.Y, coords.x, coords.y) < maxdistance) { finalPosition.x = DX; finalPosition.y = DY; } else { tryPosition.x = 0; tryPosition.y = 0; while (Pifagor(tryPosition.x, tryPosition.y) <= maxdistance) { if (sw) { tryPosition.x += sign_cd.x; if (Pifagor(tryPosition.x, tryPosition.y) > maxdistance) { break; } else { finalPosition.x += sign_cd.x; } } else { tryPosition.y += sign_cd.y; if (Pifagor(tryPosition.x, tryPosition.y) > maxdistance) { break; } else { finalPosition.y += sign_cd.y; } } sw = !sw; } } return(finalPosition); }
void Add(List <coords> Coords, int x, int y) { coords add = new coords((ushort)x, (ushort)y); if (!Coords.Contains(add)) { Coords.Add(add); } }
void UpdateChunk(object c) { coords c2 = (coords)c; int i = c2.i; int j = c2.j; int k = c2.k; chunks[i][j][k].UpdateVoxels(voxelsT[i][j][k]); //chunks[i][j][k].UpdateMesh(); }
bool Contains(List <coords> Coords, coords Check) { foreach (coords Coord in Coords) { if (Coord.X == Check.X && Check.Y == Coord.Y) { return(true); } } return(false); }
public static bool Checking(coords coordinates, string text, Button[,] array_btn) { bool row = true, collumn = true, square = true; //checking row for (int k = 0; k < 9; k++) { if (coordinates.j != k) { if (array_btn[coordinates.i, k].Text == text) { row = false; } } } //checking collumn for (int k = 0; k < 9; k++) { if (coordinates.i != k) { if (array_btn[k, coordinates.j].Text == text) { collumn = false; } } } //checking square //getting the position of the square int ii = (coordinates.i / 3) * 3; int jj = (coordinates.j / 3) * 3; for (int p = ii; p < ii + 3; p++) { for (int q = jj; q < jj + 3; q++) { if (coordinates.i != p && coordinates.j != q) { if (array_btn[p, q].Text == text) { square = false; } } } } return(square & collumn & row); }
public void HealGluth(ref WS_Creatures.CreatureObject NPC_Gluth, ref WS_Creatures.CreatureObject Zombie_Chow) { var Waypoint1 = new coords { X = 3304.919922d, Y = 3139.149902d, Z = 296.890015d, Orientation = 1.33d }; aiCreature.MoveTo((float)Waypoint1.X, (float)Waypoint1.Y, (float)Waypoint1.Z, (float)Waypoint1.Orientation); if (Conversions.ToBoolean(aiCreature.MoveTo((float)Waypoint1.X, (float)Waypoint1.Y, (float)Waypoint1.Z, (float)Waypoint1.Orientation, true))) { WS_Base.BaseUnit argAttacker = null; aiCreature.Heal(50000, Attacker: argAttacker); } }
//method that receives a button and returns its coordinates //within the given matrix public static coords GetCoordinates(Button btn, Button[,] btn_array) { coords coordinates = new coords(); for (coordinates.i = 0; coordinates.i < 9; coordinates.i++) { for (coordinates.j = 0; coordinates.j < 9; coordinates.j++) { if (btn_array[coordinates.i, coordinates.j] == btn) { return(coordinates); } } } //impossible case //MessageBox.Show(coordinates.i.ToString(), coordinates.j.ToString()); return(coordinates); }
protected int getWeakestTarget(List <int> NT, RoundConfig config, GameState gs, RobotState myself) { int t = -1; coords cd = new coords(); int min_def = 999999999; foreach (int r in NT) { if ((myself.attack * myself.energy > gs.robots[r].defence * gs.robots[r].energy) && (gs.robots[r].defence * gs.robots[r].energy < min_def)) { t = r; min_def = gs.robots[r].defence * gs.robots[r].energy; } } return(t); }
static void Main() { var input = ""; List <coords> listofCords = new List <coords>(); int appleTreesOnLand = 0; for (int i = 0; i < 3; i++) { input = Console.ReadLine(); string[] tokens = input.Split(' '); int X = Convert.ToInt32(tokens[0]); int Y = Convert.ToInt32(tokens[1]); coords xy = new coords(X, Y); listofCords.Add(xy); } int appleTrees = Convert.ToInt32(Console.ReadLine()); float areaOfLand = areaOfTriangle(listofCords[0].x, listofCords[0].y, listofCords[1].x, listofCords[1].y, listofCords[2].x, listofCords[2].y); for (int i = 0; i < appleTrees; i++) { input = Console.ReadLine(); string[] tokens = input.Split(' '); int px = Convert.ToInt32(tokens[0]); int py = Convert.ToInt32(tokens[1]); float p1 = areaOfTriangle(listofCords[0].x, listofCords[0].y, listofCords[1].x, listofCords[1].y, px, py); float p2 = areaOfTriangle(listofCords[0].x, listofCords[0].y, listofCords[2].x, listofCords[2].y, px, py); float p3 = areaOfTriangle(listofCords[2].x, listofCords[2].y, listofCords[1].x, listofCords[1].y, px, py); if (areaOfLand == p1 + p2 + p3) { appleTreesOnLand++; } } Console.WriteLine(String.Format("{0:0.0}", areaOfLand)); Console.WriteLine(appleTreesOnLand); }
protected coords getNearestRobot(List <int> RT, RoundConfig config, GameState gs, RobotState myself) { coords cd = new coords(); int dist = 9999999; int id = -1; int min_def = 999999999; foreach (RobotState r in gs.robots) { if (!RT.Contains(r.id)) { if ((getDistance(myself.X, myself.Y, r.X, r.Y) < dist) && (r.isAlive == true) && (r.id != myself.id) && (myself.attack * myself.energy > r.defence * r.energy) && (r.defence * r.energy < min_def)) { cd.X = r.X; cd.Y = r.Y; dist = getDistance(myself.X, myself.Y, r.X, r.Y); min_def = r.defence * r.energy; } } } return(cd); }
void Add(List<coords> Coords, int x, int y) { coords add = new coords((ushort)x, (ushort)y); if (!Coords.Contains(add)) Coords.Add(add); }
bool Contains(List<coords> Coords, coords Check) { foreach (coords Coord in Coords) if (Coord.X == Check.X && Check.Y == Coord.Y) return true; return false; }
/// <summary> /// /// </summary> /// <param name="seed"> /// A <see cref="System.Int32"/> /// </param> /// <returns> /// A <see cref="Room"/> /// </returns> public static Maze GrowingTree(int width, int height, int branchRate, bool nDiag, int seed, out coords StartLocation, out coords EndLocation) { return GrowingTree(width, height, branchRate, nDiag, new System.Random(seed), out StartLocation, out EndLocation); }
/// <summary> /// Based on the Growing Tree algorithm. /// </summary> /// <param name="branchRate"> /// Zero is unbiased, positive will make branches more frequent, negative will cause long passages. /// This controls the position in the list chosen: positive makes the start of the list more likely. /// Negative makes the end of the list more likely. /// Large negative values make the original point obvious. /// Try values between -10 and 10. /// </param> /// <param name="rand"> /// A <see cref="System.Random"/> /// </param> /// <returns> /// A <see cref="Room"/> /// </returns> public static Maze GrowingTree(int width, int height, int branchRate, bool nDiag, System.Random rand, out coords StartLocation, out coords EndLocation) { // The return value Maze ret = new Maze(width, height); // Initialize the grid to contain UU tiles for (int x = 0; x < width; x++){ for (int y = 0; y < height; y++){ ret[x,y] = MazeTileType.UU; } } // List of coordinates of unexposed but undetermined cells var frontier = new List<coords>(); // Functions #region Carve // This one makes the cell at (x,y) a space Action<int, int> carve = (int x, int y ) => { var extra = new List<coords>(); ret[x,y] = MazeTileType.SPACE; if (x > 0){ if (ret[x-1,y] == MazeTileType.UU){ ret[x-1,y] = MazeTileType.XU; extra.Add(new coords(x-1,y)); } } if (x < width-1){ if (ret[x+1,y] == MazeTileType.UU){ ret[x+1,y] = MazeTileType.XU; extra.Add(new coords(x+1,y)); } } if (y > 0){ if (ret[x,y-1] == MazeTileType.UU){ ret[x,y-1] = MazeTileType.XU; extra.Add(new coords(x,y-1)); } } if (y < height - 1){ if (ret[x,y+1] == MazeTileType.UU){ ret[x,y+1] = MazeTileType.XU; extra.Add(new coords(x,y+1)); } } // Add the shuffled list to the frontier frontier.AddRange(Misc.ShuffleList<coords>(extra, rand)); }; #endregion #region Harden Action<int,int> harden = (int x, int y)=> { ret[x,y] = MazeTileType.WALL; }; #endregion #region Check // Test cell at (x,y) : can this become a space? // True indicates it should become a space, false indicates // it should become a wall Func<int, int, bool, bool> check = (int x, int y, bool nodiagonals) => { int edgeState = 0; if (x > 0){ if (ret[x-1, y] == MazeTileType.SPACE){ edgeState += 1; } } if (x < width - 1){ if (ret[x+1, y] == MazeTileType.SPACE){ edgeState += 2; } } if (y > 0){ if (ret[x, y-1] == MazeTileType.SPACE){ edgeState += 4; } } if (y < height - 1){ if (ret[x,y+1] == MazeTileType.SPACE){ edgeState += 8; } } // If this would make a diagonal connection, forbid it if (nodiagonals){ if (edgeState == 1){ if (x < width-1){ if (y > 0){ if (ret[x+1,y-1] == MazeTileType.SPACE){ return false; } } if (y < height-1){ if (ret[x+1,y+1] == MazeTileType.SPACE){ return false; } } } return true; } if (edgeState == 2){ if (x > 0){ if (y > 0){ if (ret[x-1, y-1] == MazeTileType.SPACE){ return false; } } if (y < height-1){ if (ret[x-1,y+1] == MazeTileType.SPACE){ return false; } } } return true; } if (edgeState == 4){ if (y < height-1){ if (x > 0){ if (ret[x-1,y+1] == MazeTileType.SPACE){ return false; } } if (x < width-1){ if (ret[x+1,y+1] == MazeTileType.SPACE){ return false; } } } return true; } if (edgeState == 8){ if (y > 0){ if (x > 0){ if (ret[x-1, y-1] == MazeTileType.SPACE){ return false; } } if (x < width-1){ if (ret[x+1,y-1] == MazeTileType.SPACE){ return false; } } } return true; } return false; } else{ if (edgeState == 1 || edgeState == 2 || edgeState == 4 || edgeState == 8){ return true; } return false; } }; #endregion // Now that the function definitions are over, the algorithm starts // Choose an original point at random and carve it out int xChoice = rand.Next(0, width); int yChoice = rand.Next(0, height); coords tempEnd; StartLocation = tempEnd = new coords(xChoice, yChoice); carve(xChoice, yChoice); while (frontier.Count > 0){ // Select a random edge double pos = rand.NextDouble(); pos = Math.Pow(pos, Math.Exp(-branchRate)); int rIdx = (int)(pos * frontier.Count); coords choice = frontier[rIdx]; if (check(choice.X, choice.Y, nDiag)){ carve(choice.X, choice.Y); tempEnd = choice; } else{ harden(choice.X, choice.Y); } frontier.RemoveAt(rIdx); } // Set unexposed cells to be walls for (int x = 0; x < width; x++){ for (int y = 0; y < height; y++){ if (ret[x,y] == MazeTileType.UU){ ret[x,y] = MazeTileType.WALL; } } } EndLocation = tempEnd; return ret; }
public static void DDALineEx(int x0, int y0, int x1, int y1, ref List <coords> vctPoint) { if (x0 == x1 && y0 == y1) { return; } int dx = x1 - x0; int dy = y1 - y0; int abs_dx = Math.Abs(dx); int abs_dy = Math.Abs(dy); coords point = new coords(); if (abs_dx > abs_dy) { int _0_5 = abs_dx * (dy > 0 ? 1 : -1); int numerator = dy * 2; int denominator = abs_dx * 2; if (dx > 0) { for (int i = 1; i <= abs_dx; i++) { point = new coords(); point.X = x0 + i; point.Y = y0 + ((numerator * i + _0_5) / denominator); vctPoint.Add(point); } } else if (dx < 0) { for (int i = 1; i <= abs_dx; i++) { point = new coords(); point.X = x0 - i; point.Y = y0 + ((numerator * i + _0_5) / denominator); vctPoint.Add(point); } } } else { int _0_5 = abs_dy * (dx > 0 ? 1 : -1); int numerator = dx * 2; int denominator = abs_dy * 2; if (dy > 0) { for (int i = 1; i <= abs_dy; i++) { point = new coords(); point.Y = y0 + i; point.X = x0 + ((numerator * i + _0_5) / denominator); vctPoint.Add(point); } } else if (dy < 0) { for (int i = 1; i <= abs_dy; i++) { point = new coords(); point.Y = y0 - i; point.X = x0 + ((numerator * i + _0_5) / denominator); vctPoint.Add(point); } } } }
/// <summary> /// /// </summary> /// <param name="m"> /// A <see cref="Maze"/> /// </param> /// <param name="rand"> /// A <see cref="System.Random"/> /// </param> /// <returns> /// A <see cref="Room"/> /// </returns> public static Room ChambersFromMaze(Maze m, ChamberMap cm, System.Random rand, coords StartPosition, coords EndPosition) { // LEFTOFF: Here! Room ret = new Room(m.Width * Chambers.CHAMBER_WIDTH, m.Height * Chambers.CHAMBER_HEIGHT); for (int x = 0; x < m.Width; x++){ for (int y = 0; y < m.Height; y++){ // Select a random chamber type ChamberType ct; if (new coords(x,y) == EndPosition){ ct = ChamberType.TYPE_BOSS; } else{ ct = (ChamberType)(rand.Next() % (int)ChamberType.NumElements); if (ct == ChamberType.TYPE_BOSS){ ct = ChamberType.TYPE_5; } } cm[x,y] = ct; Room r = Chambers.Rooms(ct).Clone() as Room; switch(m[x,y]){ case MazeTileType.SPACE: // Handle the door carving // Left and Right if (x > 0){ if (m[x-1,y] == MazeTileType.SPACE){ Chambers.LeftDoor(r, TileType.SNOW); } } if (x < m.Width-1){ if (m[x+1,y] == MazeTileType.SPACE){ Chambers.RightDoor(r, TileType.SNOW); } } // Bottom and Top if (y > 0){ if (m[x,y-1] == MazeTileType.SPACE){ Chambers.BottomDoor(r, TileType.SNOW); } } if (y < m.Height-1){ if (m[x,y+1] == MazeTileType.SPACE){ Chambers.TopDoor(r, TileType.SNOW); } } ret.CopyRoom(r, x * Chambers.CHAMBER_WIDTH, y * Chambers.CHAMBER_HEIGHT); break; } } } return ret; }
public RobotAction Tick(int robotId, RoundConfig config, GameState state) { coords cd = new coords(); coords target_cd = new coords(); RobotState self = state.robots[robotId]; RobotAction action = new RobotAction(); List <string> friendRobots = new List <string>() { "Ryzhov", "Haritonov", "Nikandrov", "Dmitrakov", "Sinyavsky", "Frolov", "Orlov", "Kamshilov" }; int hp = self.attack + self.defence + self.speed; bool check = true; List <int> NT = new List <int>(); List <int> RT = new List <int>(); if (round == 4) { PumpDefence(ref action, self); target_cd = getNearestEnergy(friendRobots, state, self); cd = MotionTo(config, self, target_cd); action.targetId = -1; action.dX = cd.X; action.dY = cd.Y; return(action); } if (step >= config.steps - 20) { target_cd = getNearestEnergy(friendRobots, state, self); cd = MotionTo(config, self, target_cd); action.targetId = -1; PumpDefence(ref action, self); if (step == config.steps - 1) { step = 0; move = true; done = false; ooouch = false; round++; return(action); } } else { if (getAliveRobots(friendRobots, state) == 0) { target_cd = getNearestEnergy(friendRobots, state, self); cd = MotionTo(config, self, target_cd); action.targetId = -1; } else { if ((self.energy >= 0.85 * config.max_energy) && (hp >= config.max_health) && (move == true)) { //PumpAttack(ref action, self); if (check) { PumpAttack(ref action, self); if ((self.attack - self.defence >= 20) && (self.attack - self.defence <= 30)) { check = false; } } NT = getNearestTargets(friendRobots, config, state, self); if (NT.Count == 0) { RT = getRadiusTargets(friendRobots, config, state, self); target_cd = getNearestRobot(RT, config, state, self); cd = MotionTo(config, self, target_cd); action.targetId = -1; } else { action.targetId = getWeakestTarget(NT, config, state, self); } } else { if ((hp < 100) && (ooouch == false)) { ooouch = true; target_cd_extra = getFurtherEnergy(friendRobots, state, self); } move = false; if ((self.energy <= 999) && (done == false)) { if (ooouch) { cd = MotionTo(config, self, target_cd_extra); action.dX = cd.X; action.dY = cd.Y; } else { target_cd = getNearestEnergy(friendRobots, state, self); cd = MotionTo(config, self, target_cd); action.targetId = getWeakestTarget(getNearestTargets(friendRobots, config, state, self), config, state, self); } if (self.energy >= 999) { done = true; } } else { done = true; } if ((hp < 100) && (done == true)) { PumpDefence(ref action, self); target_cd = getNearestHealth(friendRobots, state, self); cd = MotionTo(config, self, target_cd); action.targetId = -1; if (hp >= 100) { done = false; } } else { done = false; } if ((self.energy >= 999) && (hp >= 100)) { move = true; check = true; ooouch = false; } } } } action.dX = cd.X; action.dY = cd.Y; step++; return(action); }
protected coords MotionTo(RoundConfig config, RobotState myself, coords cd) { coords res_cd = new coords(); coords try_cd = new coords(); int max_distance = 10 * config.max_speed * myself.speed / config.max_health * myself.energy / config.max_energy; int dx = cd.X - myself.X; int dy = cd.Y - myself.Y; coords sign_cd = new coords(); sign_cd.X = Sign(dx); sign_cd.Y = Sign(dy); res_cd.X = 0; res_cd.Y = 0; if (getDistance(myself.X, myself.Y, cd.X, cd.Y) < max_distance) { res_cd.X = dx; res_cd.Y = dy; } else { try_cd.X = 0; try_cd.Y = 0; if (dx == 0) { res_cd.X = 0; res_cd.Y = sign_cd.Y * max_distance; return(res_cd); } if (dy == 0) { res_cd.X = sign_cd.X * max_distance; res_cd.Y = 0; return(res_cd); } bool sw = false; while (Pifagor(try_cd.X, try_cd.Y) <= max_distance) { if (sw) { try_cd.X += sign_cd.X; if (Pifagor(try_cd.X, try_cd.Y) > max_distance) { break; } else { res_cd.X += sign_cd.X; } } else { try_cd.Y += sign_cd.Y; if (Pifagor(try_cd.X, try_cd.Y) > max_distance) { break; } else { res_cd.Y += sign_cd.Y; } } sw = !sw; } } return(res_cd); }
public Rect rectFromCoords(coords c) { return new Rect( Chambers.CHAMBER_WIDTH * cubeSize * c.X + BottomLeft.x, Chambers.CHAMBER_HEIGHT * cubeSize * c.Y + BottomLeft.y, Chambers.CHAMBER_WIDTH * cubeSize, Chambers.CHAMBER_HEIGHT * cubeSize); }
public RobotAction Tick(int robotId, RoundConfig config, GameState state) { int MinDistance = 999999; coords PointCoords = new coords(); RobotState self = state.robots[robotId]; RobotAction action = new RobotAction(); // расстояние до енергии foreach (Point P in state.points) { int a = TakeDistance(self.X, self.Y, P.X, P.Y); if (P.type == PointType.Energy && (a < MinDistance)) { MinDistance = a; PointCoords.x = P.X; PointCoords.y = P.Y; } } coords destination = new coords(); destination = MoveTo(self, config, PointCoords); // расстояние до жизней foreach (Point P in state.points) { int a = TakeDistance(self.X, self.Y, P.X, P.Y); if (P.type == PointType.Health && (a < MinDistance)) { MinDistance = a; PointCoords.x = P.X; PointCoords.y = P.Y; } } coords destination2 = new coords(); destination2 = MoveTo(self, config, PointCoords); action.dX = destination.x; action.dY = destination.y; //защита int maxdefdistance = 10 * config.max_radius * self.speed / config.max_health * self.energy / config.max_energy; bool attacked = false; //under_attack int enemy_id = -1; for (int id = 0; id < state.robots.Count; id++) { RobotState rstates = state.robots[id]; if (rstates.name != self.name) { int enemy_distance_attack = 10 * config.max_radius * rstates.speed / config.max_health * rstates.energy / config.max_energy; int distance = TakeDistance(self.X, self.Y, rstates.X, rstates.Y); if (distance <= enemy_distance_attack && distance <= maxdefdistance) { attacked = true; enemy_id = id; action.targetId = enemy_id; } } } if ((self.attack + self.defence + self.speed) < 0.4 * config.max_health) { action.dX = destination2.x; action.dY = destination2.y; } else if (self.energy < 0.4 * config.max_energy) { action.dX = destination.x; action.dY = destination.y; } return(action); }
public Vector3 PositionFromIdx(coords subRoomIndex, coords tileIndex) { Vector2 offset = new Vector2( BottomLeft.x + subRoomIndex.X * Chambers.CHAMBER_WIDTH * cubeSize, BottomLeft.y + subRoomIndex.Y * Chambers.CHAMBER_HEIGHT * cubeSize); return new Vector3( offset.x + cubeSize * (tileIndex.X + 0.5f), offset.y + cubeSize * (tileIndex.Y + 0.5f), 0f); }
public static void DDALineEx(int x0, int y0, int x1, int y1, ref List<coords> vctPoint) { if (x0 == x1 && y0 == y1) return; int dx = x1 - x0; int dy = y1 - y0; int abs_dx = Math.Abs(dx); int abs_dy = Math.Abs(dy); coords point = new coords(); if (abs_dx > abs_dy) { int _0_5 = abs_dx * (dy > 0 ? 1 : -1); int numerator = dy * 2; int denominator = abs_dx * 2; if (dx > 0) { for (int i = 1; i <= abs_dx; i++) { point = new coords(); point.X = x0 + i; point.Y = y0 + ((numerator * i + _0_5) / denominator); vctPoint.Add(point); } } else if (dx < 0) { for (int i = 1; i <= abs_dx; i++) { point = new coords(); point.X = x0 - i; point.Y = y0 + ((numerator * i + _0_5) / denominator); vctPoint.Add(point); } } } else { int _0_5 = abs_dy * (dx > 0 ? 1 : -1); int numerator = dx * 2; int denominator = abs_dy * 2; if (dy > 0) { for (int i = 1; i <= abs_dy; i++) { point = new coords(); point.Y = y0 + i; point.X = x0 + ((numerator * i + _0_5) / denominator); vctPoint.Add(point); } } else if (dy < 0) { for (int i = 1; i <= abs_dy; i++) { point = new coords(); point.Y = y0 - i; point.X = x0 + ((numerator * i + _0_5) / denominator); vctPoint.Add(point); } } } }
// Use this for initialization void Start() { // :o How selfish!!! Singleton = this; TextAsset t = Resources.Load(textFile) as TextAsset; //Room r = Room.FromString(t.text); //r.CopyRoom(Chambers.Rooms(ChamberSize.SIZE_1),0,0); //r.CopyRoom(Chambers.Rooms(ChamberSize.SIZE_2),20,0); //Room r = Room.ChambersGen0(width, height, numRooms); coords start = new coords(); coords end = new coords(); Maze m = Maze.GrowingTree(width, height, branchRate, noDiagonals, out start, out end); gameChambers = new ChamberMap(m.Width, m.Height); gameMaze = m; Room r = Room.ChambersFromMaze(m, gameChambers, new System.Random(), start, end); gameMap = r; MakeRoom(r, new System.Random()); if (roomControls[start.X, start.Y].PlayerStart != null){ player.transform.position = roomControls[start.X, start.Y].PlayerStart.transform.position; } else{ player.transform.position = new Vector3( BottomLeft.x + ((start.X + 0.5f) * Chambers.CHAMBER_WIDTH * cubeSize), BottomLeft.y + ((start.Y + 0.5f) * Chambers.CHAMBER_HEIGHT * cubeSize), 0); } if (firstEnemy != null){ firstEnemy.transform.position = new Vector3( BottomLeft.x + ((start.X + 0.5f) * Chambers.CHAMBER_WIDTH * cubeSize), BottomLeft.y + ((start.Y + 0.2f) * Chambers.CHAMBER_HEIGHT * cubeSize), 0); } // OK SO! // Before the game starts, turn off all rooms for (int x = 0; x < roomControls.GetLength(0); x++){ for (int y = 0; y < roomControls.GetLength(1); y++){ if (roomControls[x,y] != null){ roomControls[x,y].FreezeRoom(); } } } // Temporary! // Output the maze and the room to files /*System.IO.File.WriteAllText("mazeText.txt", m.ToString()); System.IO.File.WriteAllText("levelText.txt", r.ToString());*/ }
public intRect SubRoomRect(coords position) { return new intRect(position.X * Chambers.CHAMBER_WIDTH, position.Y * Chambers.CHAMBER_HEIGHT, Chambers.CHAMBER_WIDTH, Chambers.CHAMBER_HEIGHT); }
public Room SubRoom(coords position) { return gameMap.Slice(SubRoomRect(position)); }