backup 2022-12-25
This commit is contained in:
parent
720170f867
commit
4991f0eac8
4 changed files with 216 additions and 22 deletions
|
|
@ -1,18 +1,30 @@
|
|||
import { tractorBeam } from "./processCard";
|
||||
import { tractorBeam, moveShip } from "./processCard";
|
||||
import { Board } from "../types/GameBoard";
|
||||
import { expect } from "chai";
|
||||
import "mocha";
|
||||
import { FuelCard } from "../types/FuelCard";
|
||||
|
||||
interface test {
|
||||
name: string;
|
||||
args: [number, number];
|
||||
input: Board,
|
||||
expect: Board;
|
||||
function stringifyBoard(b: Board) {
|
||||
return [...b].map(x => x != null ? x : `-`).join(`\t`);
|
||||
};
|
||||
|
||||
interface BaseTest {
|
||||
name: string;
|
||||
input: Board;
|
||||
expect: Board;
|
||||
}
|
||||
|
||||
interface tractorTest extends BaseTest {
|
||||
args: [number, number];
|
||||
}
|
||||
|
||||
interface moveTest extends BaseTest {
|
||||
args: [number, FuelCard] | [number];
|
||||
}
|
||||
|
||||
describe("The tractorBeam function", () => {
|
||||
|
||||
const tests: test[] = [
|
||||
const tests: tractorTest[] = [
|
||||
{
|
||||
name: `should move the ships closer when equidistant`,
|
||||
args: [4, 1],
|
||||
|
|
@ -85,18 +97,8 @@ describe("The tractorBeam function", () => {
|
|||
input: [ null, null, null, "p1", "p2", "p3", null, null, null ],
|
||||
expect: [ null, null, null, "p3", "p2", "p1", null, null, null ]
|
||||
},
|
||||
// {
|
||||
// name: ``,
|
||||
// args: [4, 1],
|
||||
// input: [ ],
|
||||
// expect: [ ]
|
||||
// },
|
||||
];
|
||||
|
||||
function stringifyBoard(b: Board) {
|
||||
return [...b].map(x => x != null ? x : `-`).join(`\t`);
|
||||
};
|
||||
|
||||
for (const test of tests) {
|
||||
it(test.name, () => {
|
||||
let b = [...test.input];
|
||||
|
|
@ -105,4 +107,127 @@ describe("The tractorBeam function", () => {
|
|||
expect(stringifyBoard(b)).to.equal(stringifyBoard(test.expect));
|
||||
});
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe.only("The moveShip function [non-repulsor tests]", () => {
|
||||
const tests: moveTest[] = [
|
||||
{
|
||||
name: `should move forward when no other ships present`,
|
||||
args: [2],
|
||||
input: [ null, null, "p1", null, null, null, null ],
|
||||
expect: [ null, null, null, "p1", null, null, null ],
|
||||
},
|
||||
{
|
||||
name: `should move forwards when closest is ahead of the ship`,
|
||||
args: [0],
|
||||
input: [ "p1", null, "p2" ],
|
||||
expect: [ null, "p1", "p2" ],
|
||||
},
|
||||
{
|
||||
name: `should move backwards when closest is behind the ship`,
|
||||
args: [2],
|
||||
input: [ "p2", null, "p1" ],
|
||||
expect: [ "p2", "p1", null ],
|
||||
},
|
||||
{
|
||||
name: `should drift forwards over a single ship`,
|
||||
args: [2],
|
||||
input: [ null, null, "p1", "p2", null, null, null, ],
|
||||
expect: [ null, null, null, "p2", "p1", null, null, ],
|
||||
},
|
||||
{
|
||||
name: `should drift backwards over a single ship`,
|
||||
args: [4],
|
||||
input: [ null, null, null, "p2", "p1", null, null, ],
|
||||
expect: [ null, null, "p1", "p2", null, null, null, ],
|
||||
},
|
||||
{
|
||||
name: `should drift forwards over multiple ships`,
|
||||
args: [2],
|
||||
input: [ null, null, "p1", "p2", "p3", null, null, ],
|
||||
expect: [ null, null, null, "p2", "p3", "p1", null, ],
|
||||
},
|
||||
{
|
||||
name: `should drift backwards over multiple ships`,
|
||||
args: [4],
|
||||
input: [ null, null, "p3", "p2", "p1", null, null, ],
|
||||
expect: [ null, "p1", "p3", "p2", null, null, null, ],
|
||||
},
|
||||
{
|
||||
name: `shouldn't affect other ships`,
|
||||
args: [4],
|
||||
expect: [ null, "p2", null, null, "p1", null, "p3" ],
|
||||
input: [ null, "p2", null, null, null, "p1", "p3" ],
|
||||
},
|
||||
{
|
||||
name: `should move away from lower the edge going forwards`,
|
||||
args: [0],
|
||||
input: [ "p1", null, "p2", null ],
|
||||
expect: [ null, "p1", "p2", null ],
|
||||
},
|
||||
{
|
||||
name: `should move away from upper the edge going backwards`,
|
||||
args: [3],
|
||||
input: [ null, "p2", null, "p1" ],
|
||||
expect: [ null, "p2", "p1", null ],
|
||||
},
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
it(test.name, () => {
|
||||
let b = [...test.input];
|
||||
|
||||
if (test.args.length == 1) {
|
||||
moveShip(
|
||||
b,
|
||||
test.args[0],
|
||||
{
|
||||
"magnitude": 1,
|
||||
"symbol": "Ar",
|
||||
"name": "Argon",
|
||||
"type": "movement"
|
||||
}
|
||||
);
|
||||
} else {
|
||||
moveShip(b, ...test.args);
|
||||
};
|
||||
|
||||
expect(b).to.have.length(test.expect.length);
|
||||
expect(stringifyBoard(b)).to.equal(stringifyBoard(test.expect));
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
describe.only("The moveShip function [repulsor tests]", () => {
|
||||
const tests: moveTest[] = [
|
||||
{
|
||||
name: `should move backwards when no other ships present`,
|
||||
args: [3],
|
||||
input: [ null, null, null, "p1", null, null, null ],
|
||||
expect: [ null, null, "p1", null, null, null, null ],
|
||||
},
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
it(test.name, () => {
|
||||
let b = [...test.input];
|
||||
if (test.args.length == 1) {
|
||||
moveShip(
|
||||
b,
|
||||
test.args[0],
|
||||
{
|
||||
"magnitude": -1,
|
||||
"symbol": "Ol",
|
||||
"name": "Oliverium",
|
||||
"type": "movement"
|
||||
}
|
||||
);
|
||||
} else {
|
||||
moveShip(b, ...test.args);
|
||||
};
|
||||
expect(b).to.have.length(test.expect.length);
|
||||
expect(stringifyBoard(b)).to.equal(stringifyBoard(test.expect));
|
||||
});
|
||||
};
|
||||
})
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import { determineDirection } from "./movementDirection";
|
||||
import { Board, GamePiece } from "../types/GameBoard";
|
||||
import { FuelCard } from "../types/FuelCard";
|
||||
|
||||
|
|
@ -66,6 +67,17 @@ export function tractorBeam(board: Board, origin: number, magnitude: number) {
|
|||
};
|
||||
|
||||
/** @internal */
|
||||
export function moveShip(board: Board, shipLocation: number, fuel: FuelCard) {};
|
||||
export function moveShip(board: Board, origin: number, fuel: FuelCard) {
|
||||
let direction = determineDirection(board, origin);
|
||||
if (direction == 0) { return };
|
||||
|
||||
let newIndex = origin + ( fuel.magnitude * direction );
|
||||
while (board[newIndex] != null) {
|
||||
newIndex += direction;
|
||||
};
|
||||
|
||||
board[newIndex] = board[origin];
|
||||
board[origin] = null;
|
||||
};
|
||||
|
||||
export function processCard(board: Board, shipLocation: number, fuel: FuelCard) {};
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
export type GamePiece = string | null;
|
||||
|
||||
export type Board = GamePiece[];
|
||||
export interface Board {
|
||||
singularity: GamePiece[];
|
||||
path: GamePiece[];
|
||||
warpgate: GamePiece[];
|
||||
}
|
||||
|
|
@ -2,9 +2,62 @@ import type { Board, FuelCard, PlayerData } from "common";
|
|||
import { writable } from "svelte/store";
|
||||
|
||||
export const gameCode = writable<string>("");
|
||||
export const state = writable<string>("main-menu");
|
||||
export const state = writable<string>("game-movement");
|
||||
export const myName = writable<string>("");
|
||||
export const isHost = writable<boolean>(false);
|
||||
export const players = writable<{[index: string]: PlayerData}>({});
|
||||
export const players = writable<{[index: string]: PlayerData}>({
|
||||
a: {
|
||||
id: `a`,
|
||||
name: `Player 1`,
|
||||
host: true,
|
||||
colour: { name: `green`, hex: `#00aa00` },
|
||||
ship: { name: `shuttle`, id: `space-shuttle` },
|
||||
fuel: {
|
||||
"magnitude": 2,
|
||||
"symbol": "Jo",
|
||||
"name": "Jodium",
|
||||
"type": "stationary"
|
||||
}
|
||||
},
|
||||
b: {
|
||||
id: `b`,
|
||||
name: `Player 4`,
|
||||
host: false,
|
||||
colour: { name: `green`, hex: `#00a` },
|
||||
ship: { name: `shuttle`, id: `rocket` },
|
||||
fuel: {
|
||||
"magnitude": 1,
|
||||
"symbol": "Ar",
|
||||
"name": "Argon",
|
||||
"type": "movement"
|
||||
}
|
||||
},
|
||||
c: {
|
||||
id: `c`,
|
||||
name: `Player 3`,
|
||||
host: false,
|
||||
colour: { name: "Magenta", hex: "#b7094c" },
|
||||
ship: { name: `shuttle`, id: `rocket` },
|
||||
fuel: {
|
||||
"magnitude": 10,
|
||||
"symbol": "Mg",
|
||||
"name": "Magnesium",
|
||||
"type": "movement"
|
||||
}
|
||||
},
|
||||
d: {
|
||||
id: `d`,
|
||||
name: `Player 2`,
|
||||
host: false,
|
||||
colour: { name: "Purple", hex: "#7400b8" },
|
||||
ship: { name: `shuttle`, id: `rocket` },
|
||||
fuel: {
|
||||
"magnitude": -2,
|
||||
"symbol": "Kr",
|
||||
"name": "Krypton",
|
||||
"type": "movement"
|
||||
}
|
||||
},
|
||||
});
|
||||
export const board = writable<Board>(new Array(54).fill(null));
|
||||
export const hand = writable<FuelCard[]>([]);
|
||||
Loading…
Add table
Add a link
Reference in a new issue