public void RobotHistoryTest() { RobotHistory rh = new RobotHistory(); rh.Push(robot.Saveturn()); robot.Collect(new ToxicCargo()); float energy = robot.Energy; int load = robot.Load; float cost = robot.Cost; robot.Undo(rh.Pop()); Assert.IsTrue(energy == robot.Energy); Assert.IsTrue(load >= robot.Load); Assert.IsTrue(cost >= robot.Cost); }
public void UpdatePath(Robot robot, List <Vector2> moveList, bool isOverriding) { DestroyArrows(robot); Debug.Log("UpdatePath - isOverriding: " + isOverriding); //Handle overriding if (isOverriding) { for (int i = 0; i < robot.robotHistory.Count; i++) { RobotHistory robHist = robot.robotHistory[i]; if (robHist.time == robot.robotPrepTimer) { robot.robotHistory = robot.robotHistory.GetRange(0, i); break; } else if (robHist.time >= robot.robotPrepTimer) { robot.robotHistory = robot.robotHistory.GetRange(0, i + 1); break; } } } //Make moves list List <MoveDirection> moves = new List <MoveDirection>(); // if (paths.ContainsKey(robot.robotID)) moves = paths[robot.robotID]; // else moves = new List<MoveDirection>(); // List<MoveDirection> newMoves = Tools.VectorListToMoves(moveList); // foreach (MoveDirection move in newMoves) { // moves.Add(move); // } RobotHistory lastHist = new RobotHistory(0, robot.startTurnPos); for (int i = 0; i < robot.robotHistory.Count; i++) { RobotHistory hist = robot.robotHistory[i]; Vector2 move = hist.pos - lastHist.pos; MoveDirection moveDir = Tools.VectorToMove(move); moves.Add(moveDir); lastHist.pos = hist.pos; lastHist.time = hist.time; } //Spawn path arrows Vector2 posIncr = robot.transform.position; int c = 0; List <Transform> robotPathArrows = new List <Transform>(); for (int i = 0; i < moves.Count; i++) { MoveDirection command = moves[i]; MoveDirection nextCommand = (i == moves.Count - 1 ? MoveDirection.NONE : moves[i + 1]); Quaternion rot = Tools.MoveToRotation(command); Vector2 pos = posIncr + 1f * Tools.CommandToVector(command); Transform pathArrow = (Transform)Instantiate(pathArrowPrefab, pos, rot); pathArrow.GetComponent <SpriteRenderer>().color = new Color(1, 1, 1); //Set sprite PathType pathType = CalculatePathType(command, nextCommand); if (i < moves.Count - 1) { pathArrow.GetComponent <SpriteRenderer>().sprite = pathSpriteDict[pathType].sprite; } else { pathArrow.GetComponent <SpriteRenderer>().sprite = pathSpriteDict[PathType.END].sprite; } pathArrow.SetParent(cont.transform); posIncr += Tools.CommandToVector(command); robotPathArrows.Add(pathArrow); c++; } if (paths.ContainsKey(robot.robotID)) { paths[robot.robotID] = moves; } else { paths.Add(robot.robotID, moves); } pathArrows.Add(robot.robotID, robotPathArrows); }
public void UpdatePrepValues(float prepTimer, bool setTime = false) { // Debug.Log("/////////////////UpdatePrepValues///////////// --- prepTimer: " + prepTimer + " --- id: " + robotID); if (setTime) { robotPrepTimer = prepTimer; } Vector2 newGhostPos = ghostPos; float newGhostRot = ghostRot; RobotHistory lastStory = new RobotHistory(0, startTurnPos); foreach (RobotHistory robHist in robotHistory) { // Debug.Log("robHist: " + robHist.pos + ", " + robHist.time); if (robHist.time >= prepTimer) { if (robHist.time == prepTimer) { newGhostPos = robHist.pos; } else { float timeFrac = (prepTimer - lastStory.time) / (robHist.time - lastStory.time); Vector2 vecDiff = robHist.pos - lastStory.pos; newGhostPos = lastStory.pos + vecDiff * timeFrac; } break; } lastStory.time = robHist.time; lastStory.pos = robHist.pos; } // Debug.Log("UpdatePrepValues - newGhostPos: " + newGhostPos + ", ghostPosition: " + ghostPos + ", robotHistory: " + robotHistory.Count); rCmdCtrl.SetGhost(this, newGhostPos, newGhostRot); //TODO Simulate angle! //Simulate from start // Vector2 simulPos = pos; // float simulTimer = 0; // RobotHeight simulRobotHeight = robotHeight; // foreach (Command cmd in robotCommand.turnCommands) { // switch (cmd.cmdTyp) { // case CommandType.MOVE_TO: // float timeForCmd = RobotCommand.MoveCommandsDuration(new List<Vector2>{Vector2.right}, simulRobotHeight); // simulTimer += timeForCmd; // break; // case CommandType.GUARD: // // break; // case CommandType.SET_ANGLE: // // break; // // default: // break; // } //// float timeForCmd = RobotCommand.MoveCommandsDuration( // } }