-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from lugobots/v2
V2
- Loading branch information
Showing
46 changed files
with
1,294 additions
and
1,054 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { DIRECTION } from '.'; | ||
import * as Lugo from './proto_exported'; | ||
export default class GameSnapshotInspector { | ||
mySide: Lugo.Team.Side; | ||
myNumber: number; | ||
me: Lugo.Player; | ||
snapshot: Lugo.GameSnapshot; | ||
constructor(botSide: Lugo.Team.Side, playerNumber: number, gameSnapshot: Lugo.GameSnapshot); | ||
getSnapshot(): Lugo.GameSnapshot | null; | ||
getTurn(): number; | ||
getMe(): Lugo.Player; | ||
getBall(): Lugo.Ball | null; | ||
getPlayer(side: Lugo.Team.Side, number: number): Lugo.Player | null; | ||
getBallHolder(): Lugo.Player | null; | ||
isBallHolder(player: Lugo.Player): boolean; | ||
getTeam(side: Lugo.Team.Side): Lugo.Team | null; | ||
getMyTeam(): Lugo.Team | null; | ||
getOpponentTeam(): Lugo.Team | null; | ||
getMyTeamSide(): Lugo.Team.Side; | ||
getOpponentSide(): Lugo.Team.Side; | ||
getMyTeamPlayers(): Lugo.Player[]; | ||
getOpponentPlayers(): Lugo.Player[]; | ||
getMyTeamGoalkeeper(): Lugo.Player | null; | ||
getOpponentGoalkeeper(): Lugo.Player | null; | ||
makeOrderMove(target: Lugo.Point, speed: number): Lugo.Order; | ||
makeOrderMoveMaxSpeed(target: Lugo.Point): Lugo.Order; | ||
makeOrderMoveFromPoint(origin: Lugo.Point, target: Lugo.Point, speed: number): Lugo.Order; | ||
makeOrderMoveFromVector(direction: Lugo.Vector, speed: number): Lugo.Order; | ||
makeOrderMoveByDirection(direction: DIRECTION, speed?: number): Lugo.Order; | ||
makeOrderMoveToStop(): Lugo.Order; | ||
makeOrderJump(target: Lugo.Point, speed: number): Lugo.Order; | ||
makeOrderKick(target: Lugo.Point, speed: number): Lugo.Order; | ||
makeOrderKickMaxSpeed(target: Lugo.Point): Lugo.Order; | ||
makeOrderCatch(): Lugo.Order; | ||
private getOrientationByDirection; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var _1 = require("."); | ||
var Geo = require("./geo"); | ||
var Helpers = require("./helpers"); | ||
var ORIENTATION = require("./orentation"); | ||
var Lugo = require("./proto_exported"); | ||
var specs_1 = require("./specs"); | ||
var GameSnapshotInspector = /** @class */ (function () { | ||
function GameSnapshotInspector(botSide, playerNumber, gameSnapshot) { | ||
this.mySide = botSide; | ||
this.myNumber = playerNumber; | ||
this.snapshot = gameSnapshot; | ||
this.me = this.getPlayer(botSide, playerNumber); | ||
if (!this.me) { | ||
throw new Error("Could not find the player ".concat(botSide, "-").concat(playerNumber)); | ||
} | ||
} | ||
GameSnapshotInspector.prototype.getSnapshot = function () { | ||
return this.snapshot; | ||
}; | ||
GameSnapshotInspector.prototype.getTurn = function () { | ||
return this.snapshot.getTurn(); | ||
}; | ||
GameSnapshotInspector.prototype.getMe = function () { | ||
return this.me; | ||
}; | ||
GameSnapshotInspector.prototype.getBall = function () { | ||
var _a, _b; | ||
return (_b = (_a = this.snapshot) === null || _a === void 0 ? void 0 : _a.getBall()) !== null && _b !== void 0 ? _b : null; | ||
}; | ||
GameSnapshotInspector.prototype.getPlayer = function (side, number) { | ||
return Helpers.getPlayer(this.snapshot, side, number); | ||
}; | ||
GameSnapshotInspector.prototype.getBallHolder = function () { | ||
return Helpers.getBallHolder(this.snapshot); | ||
}; | ||
GameSnapshotInspector.prototype.isBallHolder = function (player) { | ||
return Helpers.isBallHolder(this.snapshot, player); | ||
}; | ||
GameSnapshotInspector.prototype.getTeam = function (side) { | ||
return Helpers.getTeam(this.snapshot, side); | ||
}; | ||
GameSnapshotInspector.prototype.getMyTeam = function () { | ||
return this.getTeam(this.mySide); | ||
}; | ||
GameSnapshotInspector.prototype.getOpponentTeam = function () { | ||
return this.getTeam(this.getOpponentSide()); | ||
}; | ||
GameSnapshotInspector.prototype.getMyTeamSide = function () { | ||
return this.mySide; | ||
}; | ||
GameSnapshotInspector.prototype.getOpponentSide = function () { | ||
return Helpers.getOpponentSide(this.mySide); | ||
}; | ||
GameSnapshotInspector.prototype.getMyTeamPlayers = function () { | ||
var myTeam = this.getMyTeam(); | ||
return myTeam ? myTeam.getPlayersList() : []; | ||
}; | ||
GameSnapshotInspector.prototype.getOpponentPlayers = function () { | ||
var opponentTeam = this.getOpponentTeam(); | ||
return opponentTeam ? opponentTeam.getPlayersList() : []; | ||
}; | ||
GameSnapshotInspector.prototype.getMyTeamGoalkeeper = function () { | ||
return this.getPlayer(this.getMyTeamSide(), specs_1.SPECS.GOALKEEPER_NUMBER); | ||
}; | ||
GameSnapshotInspector.prototype.getOpponentGoalkeeper = function () { | ||
return this.getPlayer(this.getOpponentSide(), specs_1.SPECS.GOALKEEPER_NUMBER); | ||
}; | ||
GameSnapshotInspector.prototype.makeOrderMove = function (target, speed) { | ||
var _a, _b; | ||
return this.makeOrderMoveFromPoint((_b = (_a = this.me) === null || _a === void 0 ? void 0 : _a.getPosition()) !== null && _b !== void 0 ? _b : Geo.newZeroedPoint(), target, speed); | ||
}; | ||
GameSnapshotInspector.prototype.makeOrderMoveMaxSpeed = function (target) { | ||
var _a, _b; | ||
return this.makeOrderMoveFromPoint((_b = (_a = this.me) === null || _a === void 0 ? void 0 : _a.getPosition()) !== null && _b !== void 0 ? _b : Geo.newZeroedPoint(), target, specs_1.SPECS.PLAYER_MAX_SPEED); | ||
}; | ||
GameSnapshotInspector.prototype.makeOrderMoveFromPoint = function (origin, target, speed) { | ||
var vec = Geo.NewVector(origin, target); | ||
var vel = Geo.NewZeroedVelocity(Geo.normalize(vec)); | ||
vel.setSpeed(speed); | ||
var moveOrder = new Lugo.Move(); | ||
moveOrder.setVelocity(vel); | ||
return new Lugo.Order().setMove(moveOrder); | ||
}; | ||
GameSnapshotInspector.prototype.makeOrderMoveFromVector = function (direction, speed) { | ||
var _a, _b, _c, _d; | ||
var targetPoint = Geo.TargetFrom(direction, (_b = (_a = this.me) === null || _a === void 0 ? void 0 : _a.getPosition()) !== null && _b !== void 0 ? _b : Geo.newZeroedPoint()); | ||
return this.makeOrderMoveFromPoint((_d = (_c = this.me) === null || _c === void 0 ? void 0 : _c.getPosition()) !== null && _d !== void 0 ? _d : Geo.newZeroedPoint(), targetPoint, speed); | ||
}; | ||
GameSnapshotInspector.prototype.makeOrderMoveByDirection = function (direction, speed) { | ||
var directionTarget = this.getOrientationByDirection(direction); | ||
return this.makeOrderMoveFromVector(directionTarget, speed !== null && speed !== void 0 ? speed : specs_1.SPECS.PLAYER_MAX_SPEED); | ||
}; | ||
GameSnapshotInspector.prototype.makeOrderMoveToStop = function () { | ||
var _a, _b, _c; | ||
var myDirection = (_c = (_b = (_a = this.getMe()) === null || _a === void 0 ? void 0 : _a.getVelocity()) === null || _b === void 0 ? void 0 : _b.getDirection()) !== null && _c !== void 0 ? _c : this.getOrientationByDirection(_1.DIRECTION.FORWARD); | ||
return this.makeOrderMoveFromVector(myDirection, 0); | ||
}; | ||
GameSnapshotInspector.prototype.makeOrderJump = function (target, speed) { | ||
var _a, _b; | ||
var vec = Geo.NewVector((_b = (_a = this.me) === null || _a === void 0 ? void 0 : _a.getPosition()) !== null && _b !== void 0 ? _b : Geo.newZeroedPoint(), target); | ||
var vel = Geo.NewZeroedVelocity(Geo.normalize(vec)); | ||
vel.setSpeed(speed); | ||
var jump = new Lugo.Jump(); | ||
jump.setVelocity(vel); | ||
return new Lugo.Order().setJump(jump); | ||
}; | ||
GameSnapshotInspector.prototype.makeOrderKick = function (target, speed) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
var ballExpectedDirection = Geo.NewVector((_c = (_b = (_a = this.snapshot) === null || _a === void 0 ? void 0 : _a.getBall()) === null || _b === void 0 ? void 0 : _b.getPosition()) !== null && _c !== void 0 ? _c : Geo.newZeroedPoint(), target); | ||
var diffVector = Geo.subVector(ballExpectedDirection, (_g = (_f = (_e = (_d = this.snapshot) === null || _d === void 0 ? void 0 : _d.getBall()) === null || _e === void 0 ? void 0 : _e.getVelocity()) === null || _f === void 0 ? void 0 : _f.getDirection()) !== null && _g !== void 0 ? _g : Geo.newZeroedPoint()); | ||
var vel = Geo.NewZeroedVelocity(Geo.normalize(diffVector)); | ||
vel.setSpeed(speed); | ||
var kick = new Lugo.Kick(); | ||
kick.setVelocity(vel); | ||
return new Lugo.Order().setKick(kick); | ||
}; | ||
GameSnapshotInspector.prototype.makeOrderKickMaxSpeed = function (target) { | ||
return this.makeOrderKick(target, specs_1.SPECS.BALL_MAX_SPEED); | ||
}; | ||
GameSnapshotInspector.prototype.makeOrderCatch = function () { | ||
var catchOrder = new Lugo.Catch(); | ||
return new Lugo.Order().setCatch(catchOrder); | ||
}; | ||
GameSnapshotInspector.prototype.getOrientationByDirection = function (direction) { | ||
var directionTarget; | ||
switch (direction) { | ||
case _1.DIRECTION.FORWARD: | ||
directionTarget = ORIENTATION.EAST; | ||
if (this.mySide === Lugo.Team.Side.AWAY) { | ||
directionTarget = ORIENTATION.WEST; | ||
} | ||
break; | ||
case _1.DIRECTION.BACKWARD: | ||
directionTarget = ORIENTATION.WEST; | ||
if (this.mySide === Lugo.Team.Side.AWAY) { | ||
directionTarget = ORIENTATION.EAST; | ||
} | ||
break; | ||
case _1.DIRECTION.LEFT: | ||
directionTarget = ORIENTATION.NORTH; | ||
if (this.mySide === Lugo.Team.Side.AWAY) { | ||
directionTarget = ORIENTATION.SOUTH; | ||
} | ||
break; | ||
case _1.DIRECTION.RIGHT: | ||
directionTarget = ORIENTATION.SOUTH; | ||
if (this.mySide === Lugo.Team.Side.AWAY) { | ||
directionTarget = ORIENTATION.NORTH; | ||
} | ||
break; | ||
case _1.DIRECTION.BACKWARD_LEFT: | ||
directionTarget = ORIENTATION.NORTH_WEST; | ||
if (this.mySide === Lugo.Team.Side.AWAY) { | ||
directionTarget = ORIENTATION.SOUTH_EAST; | ||
} | ||
break; | ||
case _1.DIRECTION.BACKWARD_RIGHT: | ||
directionTarget = ORIENTATION.SOUTH_WEST; | ||
if (this.mySide === Lugo.Team.Side.AWAY) { | ||
directionTarget = ORIENTATION.NORTH_EAST; | ||
} | ||
break; | ||
case _1.DIRECTION.FORWARD_LEFT: | ||
directionTarget = ORIENTATION.NORTH_EAST; | ||
if (this.mySide === Lugo.Team.Side.AWAY) { | ||
directionTarget = ORIENTATION.SOUTH_WEST; | ||
} | ||
break; | ||
case _1.DIRECTION.FORWARD_RIGHT: | ||
directionTarget = ORIENTATION.SOUTH_EAST; | ||
if (this.mySide === Lugo.Team.Side.AWAY) { | ||
directionTarget = ORIENTATION.NORTH_WEST; | ||
} | ||
break; | ||
default: | ||
throw new Error("unknown direction ".concat(direction)); | ||
} | ||
return directionTarget; | ||
}; | ||
return GameSnapshotInspector; | ||
}()); | ||
exports["default"] = GameSnapshotInspector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.