public static bool Advance(ref Sgame g, double time) { bool collided = false; double totaltime = 0; while (totaltime < time) { double sparetime = totaltime > chunk ? chunk : totaltime; Sgame copy = new Sgame(g, true); if (Update(ref g, sparetime, true)) { g = copy; for (int i = 0; i < rules.TICKS_PER_SECOND * chunk; i++) { if (Tick(ref g, false)) { collided = true; } } } totaltime += sparetime; } return(collided); }
public static bool Tick(ref Sgame g, bool untilCollision) { bool res = false; for (int i = 0; i < rules.MICROTICKS_PER_TICK; i++) { if (Update(ref g, oneontickspersecond / rules.MICROTICKS_PER_TICK, untilCollision)) { if (untilCollision) { return(true); } //De("collision at " + i); res = true; } } return(res); }
public Sgame(Sgame g, bool fast) { ball = new Vec(g.ball); robot = new Vec[robotsPerPlayer, 2]; for (int i = 0; i < robotsPerPlayer; i++) { for (int j = 0; j < 2; j++) { robot[i, j] = new Vec(g.robot[i, j]); } } current_tick = g.current_tick; if (!fast) { nitro_packs = new NitroPack[g.nitro_packs.Length]; for (int i = 0; i < g.nitro_packs.Length; i++) { nitro_packs[i] = CopyNitro(g.nitro_packs[i]); } players = new Player[2]; for (int i = 0; i < 2; i++) { players[i] = CopyPlayer(g.players[i]); } } else { nitro_packs = g.nitro_packs; players = g.players; } }
public void Act(Robot me, Rules rulese, Game gamee, Action action) { if ((turn == 0) && (robotsDone == 0)) { System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; rules = rulese; ar = rulese.arena; InitConstants(); firstrobot = me.id; if (me.id == 1) { firstenemyrobot = robotsPerPlayer + 1; } else { firstenemyrobot = 1; } } // if (robotsDone == 0) { start = Timenow(); if (turn > 0) { bool iscored = false, hescored = false; if (game.players[0].score != gamee.players[0].score) { iscored = true; } if (game.players[1].score != gamee.players[1].score) { hescored = true; } if (hescored || iscored) { //GOAL RESET pause = 1; //De("score"); } } game = new Sgame(gamee); if (game.ball.m != rules.BALL_MASS) { Re("nno!"); } Sgame g3 = new Sgame(game, false); Advance(ref g3, 0.25); if (g3.ball.m != rules.BALL_MASS) { Re("nno2!"); } //for (int i = 0; i < 10; i++) Tick(ref g3,false); afterball1 = new Vec(g3.ball); Advance(ref g3, 0.35); //for (int i = 0; i < 10; i++) Tick(ref g3,false); afterball = new Vec(g3.ball); bal = new Vec(game.ball); dw = bal.DanToArena(); Re("time is " + (Timenow() - start)); acts = ChooseMoves(); } if (me.id - firstrobot < acts.Length) { if (me.id - firstrobot >= 0) { action.target_velocity_x = acts[me.id - firstrobot].target_velocity_x; action.target_velocity_y = acts[me.id - firstrobot].target_velocity_y; action.target_velocity_z = acts[me.id - firstrobot].target_velocity_z; action.jump_speed = acts[me.id - firstrobot].jump_speed; } } robotsDone++; if (robotsDone == 2) { turn++; robotsDone = 0; } //int k = -9999999; //while (Timenow() - start < 20) if (k < 99999) k++; else k = -999999; }
public static bool Update(ref Sgame g, double delta_time, bool untilCollision) { bool res = false; //robot movements for (int j = 0; j < 2; j++) { for (int i = 0; i < robotsPerPlayer; i++) { g.robot[j, i].Move(delta_time); } } //radium adjustment //move ball g.ball.Move(delta_time); //collide robots for (int j = 0; j < 2; j++) { for (int i = 0; i < robotsPerPlayer; i++) { for (int j2 = 0; j2 < 2; j2++) { for (int i2 = 0; i2 < robotsPerPlayer; i2++) { if (!((i == i2) && (j == j2))) { if (Collide_vectors(ref g.robot[j, i], ref g.robot[j2, i2])) { //robot collision res = true; } } } } } } //collide robot-ball and robot-arena for (int j = 0; j < 2; j++) { for (int i = 0; i < robotsPerPlayer; i++) { // robot-ball collision //if (Collide_vectors(ref g.robot[j, i], ref g.ball)) // res = true; if (CollideWithArena(ref g.robot[j, i], false)) { res = true; } } } //ball collide with arena if (CollideWithArena(ref g.ball, false)) { // De("collision: " + v); // De("becomes : " + ballon); res = true; } // goal check //nitro distances check //g.ball = ballon.ToBall(); return(res); }