Skip to content

Commit 72426c1

Browse files
committed
Merge branch 'master' into client-release
2 parents 4478d93 + 3d2a4ff commit 72426c1

File tree

16 files changed

+187
-91
lines changed

16 files changed

+187
-91
lines changed

client/src/components/sidebar/map-editor/MapGenerator.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,27 @@ function verifyMap(map: CurrentMap, bodies: Bodies): string {
147147
// Validate initial bodies
148148
for (const body of bodies.bodies.values()) {
149149
// Check distance from cat to other cats and cheese mines
150+
let body_type = undefined
151+
switch (body.robotType) {
152+
case RobotType.CAT:
153+
body_type = 'Cat'
154+
break
155+
case RobotType.RAT:
156+
body_type = 'Rat'
157+
break
158+
case RobotType.RAT_KING:
159+
body_type = 'Rat King'
160+
break
161+
default:
162+
body_type = 'Unknown'
163+
}
150164

151165
for (const checkCheeseMine of map.staticMap.cheeseMines) {
152-
if (squareIntersects(checkCheeseMine, body.pos, 4)) {
166+
if (squareIntersects(checkCheeseMine, body.pos, 2)) {
153167
return (
154-
`Cheese mine at (${checkCheeseMine.x}, ${checkCheeseMine.y}) is too close to cheese mine ` +
168+
`Cheese mine at (${checkCheeseMine.x}, ${checkCheeseMine.y}) is too close to ${body_type} ` +
155169
`at (${body.pos.x}, ${body.pos.y}), must be ` +
156-
`>= 5 away`
170+
`>= 3 away`
157171
)
158172
}
159173
}
@@ -162,7 +176,7 @@ function verifyMap(map: CurrentMap, bodies: Bodies): string {
162176
if (checkBody === body) continue
163177
if (squareIntersects(checkBody.pos, body.pos, 0)) {
164178
return (
165-
`Cat at (${body.pos.x}, ${body.pos.y}) is too close to cat ` +
179+
`${body_type} at (${body.pos.x}, ${body.pos.y}) is too close to cat ` +
166180
`at (${checkBody.pos.x}, ${checkBody.pos.y}), must be ` +
167181
`>= 1 away`
168182
)
@@ -175,7 +189,7 @@ function verifyMap(map: CurrentMap, bodies: Bodies): string {
175189
if (wall !== -1) {
176190
const pos = map.indexToLocation(wall)
177191
return (
178-
`Cat at (${body.pos.x}, ${body.pos.y}) is too close to wall ` +
192+
`${body_type} at (${body.pos.x}, ${body.pos.y}) is too close to wall ` +
179193
`at (${pos.x}, ${pos.y}), must be ` +
180194
`>= 3 away`
181195
)

client/src/playback/Actions.ts

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export default class Actions {
4646
//this.actions.splice(i, 1)
4747

4848
// Otherwise, this is faster
49-
this.actions[i] = this.actions[this.actions.length - 1]
50-
this.actions[i].finish(round)
49+
[this.actions[i], this.actions[this.actions.length-1]] = [this.actions[this.actions.length - 1], this.actions[i]]
50+
this.actions[this.actions.length-1].finish(round)
5151
this.actions.pop()
5252

5353
i--
@@ -109,22 +109,23 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
109109
const random2 = ((src.pos.x * 259 + src.pos.y * 429 + match.currentRound.roundNumber * 224) / 100) % 1
110110
const interpolationFactor = match.getInterpolationFactor()
111111

112-
ctx.save()
113-
ctx.globalAlpha = 0.5 - 0.5 * interpolationFactor * interpolationFactor
114-
ctx.fillStyle = '#000000'
115-
ctx.font = '0.4px Arial'
116-
// parabolic trajectory.
117-
const fontX = coords.x + (4 * random1 - 2) * interpolationFactor - 0.5
118-
const fontY =
119-
coords.y - (2 + 4 * random2) * interpolationFactor + 8 * interpolationFactor * interpolationFactor - 0.5
120-
ctx.fillText('nom', fontX, fontY)
112+
// ctx.save()
113+
// ctx.globalAlpha = 0.5 - 0.5 * interpolationFactor * interpolationFactor
114+
// ctx.fillStyle = '#000000'
115+
// ctx.font = '0.4px Arial'
116+
// // parabolic trajectory.
117+
// const fontX = coords.x + (4 * random1 - 2) * interpolationFactor - 0.5
118+
// const fontY =
119+
// coords.y - (2 + 4 * random2) * interpolationFactor + 8 * interpolationFactor * interpolationFactor - 0.5
120+
// ctx.fillText('nom', fontX, fontY)
121+
src.textureOverride = true
121122
src.imgPath = `robots/cat/cat_feed_${src.direction}.png`// is reset in `finish`.
122-
ctx.restore()
123+
// ctx.restore()
123124
}
124125

125126
finish(round: Round): void {
126127
const src = round.bodies.getById(this.robotId)
127-
src.imgPath = 'robots/cat/cat.png'
128+
src.textureOverride = false
128129
}
129130
},
130131
[schema.Action.RatAttack]: class AttackAction extends Action<schema.RatAttack> {
@@ -183,18 +184,30 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
183184
}
184185
},
185186
[schema.Action.RatNap]: class RatNapAction extends Action<schema.RatNap> {
186-
private static readonly OFFSET = { x: -0.35, y: 0 }
187+
// private static readonly OFFSET = { x: -0.35, y: 0 }
187188
apply(round: Round): void {
188189
// move the target onto the source adjust target's size using scale factor
189190
const src = round.bodies.getById(this.robotId)
190191
const target = round.bodies.getById(this.actionData.id()) // rat getting napped
191192

192-
target.carriedRobot = undefined
193-
src.carriedRobot = target.id
194-
195-
target.lastPos = { ...target.pos }
196-
target.pos = { x: src.pos.x + RatNapAction.OFFSET.x, y: src.pos.y + RatNapAction.OFFSET.y }
197-
target.size = 0.6
193+
if (target.beingCarried) {
194+
// drop the target
195+
const carrier = round.bodies.getById(target.carrierRobot!)
196+
carrier.carriedRobot = undefined
197+
target.size = 1
198+
target.beingCarried = false
199+
target.carrierRobot = undefined
200+
} else {
201+
// pick up the target
202+
src.carriedRobot = target.id
203+
target.carrierRobot = src.id
204+
target.carriedRobot = undefined
205+
target.beingCarried = true
206+
207+
target.lastPos = { ...target.pos }
208+
// target.pos = { x: src.pos.x + RatNapAction.OFFSET.x, y: src.pos.y + RatNapAction.OFFSET.y }
209+
target.size = 0.6
210+
}
198211
}
199212
draw(match: Match, ctx: CanvasRenderingContext2D): void {
200213
//target rat moves onto src rat, circle around carried group thing
@@ -219,7 +232,6 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
219232
ctx.arcTo(srcCoords.x - half, srcCoords.y - half, srcCoords.x + half, srcCoords.y - half, radius)
220233
ctx.stroke()
221234
ctx.restore()
222-
ctx.restore()
223235
}
224236
},
225237
[schema.Action.RatCollision]: class RatCollisionAction extends Action<schema.RatCollision> {
@@ -377,10 +389,14 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
377389
[schema.Action.CatScratch]: class CatScratchAction extends Action<schema.CatScratch> {
378390
draw(match: Match, ctx: CanvasRenderingContext2D): void {
379391
// cat scratching animation
380-
381392
const body = match.currentRound.bodies.getById(this.robotId)
382393
const pos = match.map.indexToLocation(this.actionData.loc())
383394
const coords = renderUtils.getRenderCoords(pos.x, pos.y, match.map.dimension, true)
395+
396+
const dir = body.direction
397+
body.textureOverride = true
398+
body.imgPath = `robots/cat/cat_scratch_${dir}.png`
399+
384400
const reflected = body.pos.x < pos.x
385401

386402
const interpolationFactor = match.getInterpolationFactor()
@@ -399,12 +415,11 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
399415
}
400416
ctx.stroke()
401417
ctx.globalAlpha = 1
402-
body.imgPath = `robots/cat/cat_scratch_${body.direction}.png`
403418
}
404419

405420
finish(round: Round): void {
406421
const body = round.bodies.getById(this.robotId)
407-
body.imgPath = 'robots/cat/cat.png'
422+
body.textureOverride = false
408423
}
409424
},
410425
[schema.Action.CatPounce]: class CatPounceAction extends Action<schema.CatPounce> {
@@ -413,6 +428,7 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
413428
const body = round.bodies.getById(this.robotId)
414429
const startPos = round.map.indexToLocation(this.actionData.startLoc())
415430
const endPos = round.map.indexToLocation(this.actionData.endLoc())
431+
console.log('pounce from', startPos, 'to', endPos)
416432
}
417433
draw(match: Match, ctx: CanvasRenderingContext2D): void {
418434
// cat pouncing animation
@@ -423,6 +439,7 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
423439
const endCoords = renderUtils.getRenderCoords(endPos.x, endPos.y, match.map.dimension, true)
424440
const angle = Math.atan2(endPos.y - startPos.y, endPos.x - startPos.x)
425441

442+
body.textureOverride = true
426443
let texture: string
427444
if (angle >= (7 * Math.PI) / 4 || angle <= Math.PI / 4) {
428445
texture = 'robots/cat/cat_pounce_5.png'
@@ -446,7 +463,7 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
446463
}
447464
finish(round: Round): void {
448465
const body = round.bodies.getById(this.robotId)
449-
body.imgPath = 'robots/cat/cat.png'
466+
body.textureOverride = false
450467
}
451468
},
452469
[schema.Action.PlaceTrap]: class PlaceTrapAction extends Action<schema.PlaceTrap> {
@@ -500,7 +517,8 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
500517
draw(match: Match, ctx: CanvasRenderingContext2D): void {
501518
// trap triggering animation
502519
const body = match.currentRound.bodies.getById(this.robotId)
503-
const pos = match.map.indexToLocation(this.actionData.loc())
520+
// const pos = match.map.indexToLocation(this.actionData.loc())
521+
const pos = body.getInterpolatedCoords(match)
504522
const coords = renderUtils.getRenderCoords(pos.x, pos.y, match.map.dimension, true)
505523

506524
const size = body.size - 1
@@ -546,6 +564,14 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
546564
// maybe move rat to target loc
547565
const body = round.bodies.getById(this.robotId)
548566
const endLoc = round.map.indexToLocation(this.actionData.loc())
567+
if( body.carriedRobot !== undefined ) {
568+
const carrier = round.bodies.getById(body.carriedRobot)
569+
carrier.carriedRobot = undefined
570+
}
571+
body.carrierRobot = undefined
572+
body.beingCarried = false
573+
body.size = 1
574+
body.pos = { ...endLoc }
549575
}
550576
draw(match: Match, ctx: CanvasRenderingContext2D): void {
551577
const body = match.currentRound.bodies.getById(this.robotId)
@@ -555,15 +581,15 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
555581

556582
const from = pos
557583
const to = match.currentRound.map.indexToLocation(this.actionData.loc())
558-
584+
console.log('throw from', from, 'to', to)
559585
const dx = to.x - from.x
560586
const dy = to.y - from.y
561587
const mag = Math.hypot(dx, dy)
562588
if (mag < 1e-3) return
563589

564590
const ux = dx / mag
565591
const uy = dy / mag
566-
const px = -uy
592+
const px = uy
567593
const py = ux
568594

569595
// deterministic jitter
@@ -583,10 +609,10 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
583609
const offset = i * spacing
584610
const jitter = (r - 0.5) * 0.15
585611

586-
const endX = coords.x - ux * 0.3 + px * offset + px * jitter
612+
const endX = coords.x + ux * 0.3 + px * offset + px * jitter
587613
const endY = coords.y - uy * 0.3 + py * offset + py * jitter
588614

589-
const startX = endX - ux * baseLength
615+
const startX = endX + ux * baseLength
590616
const startY = endY - uy * baseLength
591617

592618
ctx.beginPath()
@@ -655,16 +681,15 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
655681
draw(match: Match, ctx: CanvasRenderingContext2D): void {
656682
const body = match.currentRound.bodies.getById(this.robotId)
657683
const renderCoords = renderUtils.getRenderCoords(
658-
body.pos.x - 1 + body.size / 2,
659-
body.pos.y + body.size / 2,
684+
body.pos.x,
685+
body.pos.y,
660686
match.map.dimension,
661-
true
662687
)
663688
renderUtils.renderCenteredImageOrLoadingIndicator(
664689
ctx,
665690
getImageIfLoaded('robots/squeak.png'),
666691
renderCoords,
667-
1
692+
body.size
668693
)
669694
}
670695
},

client/src/playback/Bodies.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,11 @@ export class Body {
364364
public actionCooldown: number = 0
365365
public turningCooldown: number = 0
366366
public carriedRobot: number | undefined = undefined // id of carried robot
367+
public carrierRobot: number | undefined = undefined // id of robot carrying this robot
368+
public beingCarried: boolean = false
367369
public bytecodesUsed: number = 0
368370
public cheese: number = 0
371+
public textureOverride: boolean = false
369372

370373
constructor(
371374
private game: Game,
@@ -428,7 +431,13 @@ export class Body {
428431
}
429432

430433
public draw(match: Match, ctx: CanvasRenderingContext2D): void {
434+
const OFFSET = { x: .35, y: 0 } // to center the rat on the tile
435+
const ratnapped = this.robotType === schema.RobotType.RAT && this.beingCarried
436+
437+
if(ratnapped) this.pos.x += OFFSET.x
431438
const pos = this.getInterpolatedCoords(match)
439+
if(ratnapped) this.pos.x -= OFFSET.x
440+
432441
const renderCoords = renderUtils.getRenderCoords(pos.x, pos.y, match.currentRound.map.staticMap.dimension)
433442

434443
if (this.robotType == schema.RobotType.CAT) {
@@ -792,7 +801,7 @@ export const BODY_DEFINITIONS: Record<schema.RobotType, typeof Body> = {
792801

793802
public draw(match: Match, ctx: CanvasRenderingContext2D): void {
794803
const dir = this.direction
795-
this.imgPath = `robots/${this.team.colorName.toLowerCase()}/rat_${dir}_64x64.png`
804+
if (!this.textureOverride) this.imgPath = `robots/${this.team.colorName.toLowerCase()}/rat_${dir}_64x64.png`
796805
super.draw(match, ctx)
797806
}
798807
},
@@ -810,7 +819,7 @@ export const BODY_DEFINITIONS: Record<schema.RobotType, typeof Body> = {
810819

811820
public draw(match: Match, ctx: CanvasRenderingContext2D): void {
812821
const dir = this.direction
813-
this.imgPath = `robots/${this.team.colorName.toLowerCase()}/rat_king_64x64.png`
822+
if (!this.textureOverride) this.imgPath = `robots/${this.team.colorName.toLowerCase()}/rat_king_64x64.png`
814823
super.draw(match, ctx)
815824
}
816825
},
@@ -828,7 +837,7 @@ export const BODY_DEFINITIONS: Record<schema.RobotType, typeof Body> = {
828837

829838
public draw(match: Match, ctx: CanvasRenderingContext2D): void {
830839
const dir = this.direction
831-
this.imgPath = `robots/cat/cat_${dir}.png`
840+
if (!this.textureOverride) this.imgPath = `robots/cat/cat_${dir}.png`
832841
super.draw(match, ctx)
833842
}
834843
}

client/src/playback/Map.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ export class CurrentMap {
318318
if (ratTrap) {
319319
info.push('Rat Trap')
320320
}
321-
if (ratTrap) {
321+
if (catTrap) {
322322
info.push('Cat Trap')
323323
}
324324
if (cheese) {
438 KB
Loading
436 KB
Loading

engine/src/main/battlecode/common/GameConstants.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public class GameConstants {
8989
public static final double CHEESE_COOLDOWN_PENALTY = 0.01;
9090

9191
/** The amount of cheese the rat king consumes each round. */
92-
public static final int RAT_KING_CHEESE_CONSUMPTION = 3;
92+
public static final int RAT_KING_CHEESE_CONSUMPTION = 2;
9393

9494
/** The amount of health the rat king loses by not eating cheese. */
9595
public static final int RAT_KING_HEALTH_LOSS = 10;
@@ -101,16 +101,16 @@ public class GameConstants {
101101
public static final int SQ_CHEESE_SPAWN_RADIUS = 4;
102102

103103
/** How much cheese each mine spawns at once */
104-
public static final int CHEESE_SPAWN_AMOUNT = 5;
104+
public static final int CHEESE_SPAWN_AMOUNT = 20;
105105

106106
/** The number of rat kings a player starts with. */
107107
public static final int NUMBER_INITIAL_RAT_KINGS = 1;
108108

109-
/**
110-
* The maximum distance for transferring cheese to an allied rat king or
111-
* dropping it on the ground
112-
*/
113-
public static final int CHEESE_DROP_RADIUS_SQUARED = 9;
109+
/** The maximum distance for transferring cheese to an allied rat king */
110+
public static final int CHEESE_TRANSFER_RADIUS_SQUARED = 9;
111+
112+
/** The maximum distance for picking up cheese on the map */
113+
public static final int CHEESE_PICK_UP_RADIUS_SQUARED = 2;
114114

115115
/** The maximum distance from a rat king for building robots */
116116
public static final int BUILD_ROBOT_RADIUS_SQUARED = 4;

engine/src/main/battlecode/common/MapInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public boolean isWall() {
5050
}
5151

5252
/**
53-
* Returns if this square is a wall.
53+
* Returns if this square is a dirt.
5454
*
55-
* @return whether this square is a wall
55+
* @return whether this square is dirt
5656
*
5757
* @battlecode.doc.costlymethod
5858
*/

engine/src/main/battlecode/common/RobotController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,15 @@ public interface RobotController {
586586
*/
587587
boolean canTurn();
588588

589+
/**
590+
* Checks whether this robot can turn to the specified direction.
591+
* Effectively just canTurn() with an extra check that d is not null
592+
* and not {@link Direction#CENTER}.
593+
*
594+
* @param d the direction to turn to
595+
*/
596+
boolean canTurn(Direction d);
597+
589598
/**
590599
* Turns to the specified direction
591600
*

0 commit comments

Comments
 (0)