Skip to content

Commit

Permalink
Fix tpyes
Browse files Browse the repository at this point in the history
  • Loading branch information
Petah committed Sep 4, 2020
1 parent f8f8f61 commit c433305
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/lib/randomMove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BTData, BTRequest } from '../types/BTData';
import { MoveDirection } from '../types/MoveDirection';
import { shuffle } from './shuffle';

export function randomMove(request: BTRequest) {
export function randomMove(request: BTRequest): MoveDirection {
let direction, x, y;
const directions = [MoveDirection.LEFT, MoveDirection.RIGHT, MoveDirection.UP, MoveDirection.DOWN];
shuffle(directions);
Expand Down Expand Up @@ -36,4 +36,5 @@ export function randomMove(request: BTRequest) {
}
}
log('randomMove', 'no-options');
return direction;
}
2 changes: 1 addition & 1 deletion src/server/snakes/aldo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Aldo extends BaseSnake implements ISnake {
public headType = HeadType.TONGUE;
public tailType = TailType.SKINNY;

public move(request: BTRequest): ServerMoveResponse {
public move(request: BTRequest): ServerMoveResponse | null {
// if (!request.storage.xDirection) {
// if (y % 2 === 0) {
// request.storage.xDirection = request.storage.xDirection || MoveDirection.RIGHT;
Expand Down
5 changes: 3 additions & 2 deletions src/server/snakes/base-snake.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Server } from '../Server';
import { Server, ServerMoveResponse } from '../Server';
import { BTRequest } from '../../types/BTData';
import { MoveDirection } from '../../types/MoveDirection';

Expand All @@ -22,7 +22,7 @@ export abstract class BaseSnake {
public start(request: BTRequest): void {
}

public move(request: BTRequest) {
public move(request: BTRequest): ServerMoveResponse | null {
let direction;
for (const state of this.states) {
if (direction = state(request)) {
Expand All @@ -33,6 +33,7 @@ export abstract class BaseSnake {
};
}
}
return null;
}

public get name() {
Expand Down
3 changes: 2 additions & 1 deletion src/server/snakes/dunno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import { BaseSnake } from './base-snake';
import { moveTowardsKill } from '../../lib/moveTowardsKill';
import { lookAhead } from '../../lib/lookAhead';
import { ISnake } from './snake-interface';
import { ServerMoveResponse } from '../Server';

export class Dunno extends BaseSnake implements ISnake {
public port: number = 9007;
public color = Color.NEPHRITIS;
public headType = HeadType.SAND_WORM;
public tailType = TailType.PIXEL;

public move(request: BTRequest): ServerMoveResponse {
public move(request: BTRequest): ServerMoveResponse | null {
let direction;
direction = moveTowardsFoodPf(request);
if (!direction) {
Expand Down
2 changes: 1 addition & 1 deletion src/server/snakes/keep-away.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class KeepAway extends BaseSnake implements ISnake {
public headType = HeadType.DEAD;
public tailType = TailType.CURLED;

public move(request: BTRequest): ServerMoveResponse {
public move(request: BTRequest): ServerMoveResponse | null {
let direction;
if (request.body.you.health < 10) {
direction = moveTowardsFoodPf(request);
Expand Down
2 changes: 1 addition & 1 deletion src/server/snakes/look-ahead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class LookAhead extends BaseSnake implements ISnake {
public headType = HeadType.EVIL;
public tailType = TailType.SHARP;

public move(request: BTRequest): ServerMoveResponse {
public move(request: BTRequest): ServerMoveResponse | null {
return {
move: lookAhead(request.body),
};
Expand Down
2 changes: 1 addition & 1 deletion src/server/snakes/project-z-2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class ProjectZ2 extends BaseSnake implements ISnake {
public headType = HeadType.SILLY;
public tailType = TailType.ROUND_BUM;

public move(request: BTRequest): ServerMoveResponse {
public move(request: BTRequest): ServerMoveResponse | null {
let direction;
direction = moveTowardsFoodPf(request);
if (!direction) {
Expand Down
2 changes: 1 addition & 1 deletion src/server/snakes/project-z.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class ProjectZ extends BaseSnake implements ISnake {
public headType = HeadType.BELUGA;
public tailType = TailType.BLOCK_BUM;

public move(request: BTRequest): ServerMoveResponse {
public move(request: BTRequest): ServerMoveResponse | null {
let direction;
// Only go for food if smaller than other snake -2
direction = moveTowardsFoodPf(request);
Expand Down
2 changes: 1 addition & 1 deletion src/server/snakes/rando.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class Rando extends BaseSnake implements ISnake {
public headType = HeadType.REGULAR;
public tailType = TailType.FAT_RATTLE;

public move(request: BTRequest): ServerMoveResponse {
public move(request: BTRequest): ServerMoveResponse | null {
let direction;
if (request.body.you.health < 20) {
direction = moveTowardsFoodPf(request);
Expand Down
5 changes: 3 additions & 2 deletions src/server/snakes/tak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { BaseSnake } from './base-snake';
import { ISnake } from './snake-interface';
import { isEnemy } from '../../lib/isEnemy';
import { ServerMoveResponse } from '../Server';
import { MoveDirection } from '../../types/MoveDirection';

export class Tak extends BaseSnake implements ISnake {
public port: number = 9004;
Expand All @@ -18,8 +19,8 @@ export class Tak extends BaseSnake implements ISnake {
public headType = HeadType.FANG;
public tailType = TailType.FRECKLED;

public move(request: BTRequest): ServerMoveResponse {
let direction;
public move(request: BTRequest): ServerMoveResponse | null {
let direction: MoveDirection;
let biggestSnake = 0;
for (const snake of request.body.board.snakes) {
if (!isEnemy(request.body.you, snake)) {
Expand Down
24 changes: 12 additions & 12 deletions src/server/snakes/work-it-out.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ export class WorkItOut extends BaseSnake implements ISnake {
// };
// }

public move(request: BTRequest): ServerMoveResponse {
let direction;
for (const op of this.ops) {
direction = op(request);
if (direction) {
break;
}
}
return {
move: direction,
};
}
// public move(request: BTRequest): ServerMoveResponse | null {
// let direction;
// for (const op of this.ops) {
// direction = op(request);
// if (direction) {
// break;
// }
// }
// return {
// move: direction,
// };
// }
}

0 comments on commit c433305

Please sign in to comment.