Skip to content

Commit

Permalink
color + wip: bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wighawag committed Aug 31, 2023
1 parent 6a414f2 commit c8c11f3
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 41 deletions.
54 changes: 54 additions & 0 deletions common/src/draft.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// computeDelta(position: bigint, newColor: Color): {newDelta: number; newEnemymask: number} {
// const {x, y} = bigIntIDToXY(position);
// const data = {
// newDelta: 0,
// newEnemymask: 0,
// };

// {
// const upPosition = xyToBigIntID(x, y - 1);
// const color = this.getCellInMemory(upPosition).color;
// if (color != Color.None) {
// const enemyOrFriend = color == newColor ? 1 : -1;
// if (enemyOrFriend < 0) {
// data.newEnemymask = data.newEnemymask | 1;
// }
// data.newDelta += enemyOrFriend;
// }
// }
// {
// const leftPosition = xyToBigIntID(x - 1, y);
// const color = this.getCellInMemory(leftPosition).color;
// if (color != Color.None) {
// const enemyOrFriend = color == newColor ? 1 : -1;
// if (enemyOrFriend < 0) {
// data.newEnemymask = data.newEnemymask | 1;
// }
// data.newDelta += enemyOrFriend;
// }
// }

// {
// const downPosition = xyToBigIntID(x, y + 1);
// const color = this.getCellInMemory(downPosition).color;
// if (color != Color.None) {
// const enemyOrFriend = color == newColor ? 1 : -1;
// if (enemyOrFriend < 0) {
// data.newEnemymask = data.newEnemymask | 1;
// }
// data.newDelta += enemyOrFriend;
// }
// }
// {
// const rightPosition = xyToBigIntID(x + 1, y);
// const color = this.getCellInMemory(rightPosition).color;
// if (color != Color.None) {
// const enemyOrFriend = color == newColor ? 1 : -1;
// if (enemyOrFriend < 0) {
// data.newEnemymask = data.newEnemymask | 1;
// }
// data.newDelta += enemyOrFriend;
// }
// }
// return data;
// }
12 changes: 6 additions & 6 deletions common/src/stratagems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ export function xyToBigIntID(x: number, y: number): bigint {

export enum Color {
None = 0,
Blue = 1,
Red = 2,
Green = 3,
Yellow = 4,
Purple = 5,
Evil = 6,
Blue = 1, // 5ab9bb
Red = 2, // c5836e
Green = 3, // 8bffcb
Yellow = 4, // d3d66d
Purple = 5, // a9799d
Evil = 6, // 3d3d3d
}

export type ContractCell = {
Expand Down
7 changes: 5 additions & 2 deletions contracts/src/game/debug/StratagemsDebug.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ contract StratagemsDebug is UsingStratagemsSetters, UsingControlledTime, IStrata
// we act as if the token were added in previous epochs
// this is so it does not affect the resolution phase
int256 potentialLife = int256(uint256(cell.life)) - cell.delta;
if (potentialLife <= 0) {
if (potentialLife < 0) {
potentialLife = 0;
}
if (uint256(potentialLife) > MAX_LIFE) {
unchecked {
int256 x = int256(int32(int256(uint256(position) & 0xFFFFFFFF)));
int256 y = int256(int32(int256(uint256(position) >> 32)));
require(
potentialLife > 0,
uint256(potentialLife) > MAX_LIFE,
string.concat('INVALID_LIFE_CONFIGURATION: ', Strings.toString(x), ',', Strings.toString(y))
);
}
Expand Down
56 changes: 56 additions & 0 deletions contracts/test/scenarios/example_08.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
$01: 2
$02: 0
$03: 0
-------------------------
| | | | | |
| | | | | |
-------------------------
| R3 | R4 | R0 | B0 | |
| 02 | 02 | 03 | 03 | |
-------------------------
| | B0 | R0 | | |
| | 02 | 02 | | |
-------------------------
| | | | | |
| | | | | |
-------------------------
| | | | | |
| | | | | |
-------------------------
+
-------------------------
| | | | | |
| | | | | |
-------------------------
| | |+B | | |
| | | 01 | | |
-------------------------
| | |+B | | |
| | | 01 | | |
-------------------------
| | | | | |
| | | | | |
-------------------------
| | | | | |
| | | | | |
-------------------------
=
-------------------------
| | | | | |
| | | | | |
-------------------------
| R4 | R3 | B2 | B0 | |
| 02 | 02 | 01 | 03 | |
-------------------------
| | B0 | B3 | | |
| | 02 | 01 | | |
-------------------------
| | | | | |
| | | | | |
-------------------------
| | | | | |
| | | | | |
-------------------------
$01: 0
$02: 2
$03: 2
2 changes: 1 addition & 1 deletion web/src/lib/action/ActionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class ActionHandler {
const currentMove = currentOffchainState.moves?.find((v) => v.x === x && v.y === y);
if (currentMove) {
accountData.offchainState.removeMove(x, y);
const color = ((currentMove.color + 1) % 5) as Color;
const color = ((currentMove.color + 1) % 6) as Color;
if (color > 0) {
accountData.offchainState.addMove({x, y, color, player});
}
Expand Down
25 changes: 1 addition & 24 deletions web/src/lib/blockchain/state/Epoch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function computeEpoch(time: number) {
const RESOLUTION_PHASE_DURATION = TOTAL - ACTION_PERIOD;
const START_TIME = 0;
// --------------------

// From Solidity
const epochDuration = COMMIT_PHASE_DURATION + RESOLUTION_PHASE_DURATION;
// const time = _timestamp();
const timePassed = time - START_TIME;
Expand All @@ -25,29 +25,6 @@ export function computeEpoch(time: number) {
const timeLeftToReveal = isActionPhase ? -1 : epochDuration - timePassedFromEpochStart;
const timeLeftToEpochEnd = epochDuration - timePassedFromEpochStart;
return {epoch, timeLeftToEpochEnd, timeLeftToReveal, timeLeftToCommit, isActionPhase};

// const totalTimePassed = time;
// const epoch = Math.floor(totalTimePassed / TOTAL + 1);
// const epochStartTime = (epoch - 1) * TOTAL;
// const timePassed = time - epochStartTime;
// const isActionPhase = timePassed < ACTION_PERIOD;
// const timeLeftToCommit = ACTION_PERIOD - timePassed;
// const timeLeftToReveal = isActionPhase ? -1 : TOTAL - timePassed;
// const timeLeftToEpochEnd = TOTAL - timePassed;
// return {epoch, timeLeftToEpochEnd, timeLeftToReveal, timeLeftToCommit, isActionPhase};
/*
uint256 epochDuration = COMMIT_PHASE_DURATION + RESOLUTION_PHASE_DURATION;
console.log(COMMIT_PHASE_DURATION);
console.log(RESOLUTION_PHASE_DURATION);
console.log(START_TIME);
console.log(epochDuration);
uint256 time = _timestamp();
console.log(time);
require(time >= START_TIME, 'GAME_NOT_STARTED');
uint256 timePassed = time - START_TIME;
epoch = uint32(timePassed / epochDuration + 2); // epoch start at 2, this make the hypothetical previous resolution phase's epoch to be 1
commiting = timePassed - ((epoch - 2) * epochDuration) < COMMIT_PHASE_DURATION;
*/
}

export type EpochState = {
Expand Down
2 changes: 1 addition & 1 deletion web/src/lib/render/PIXICanvas.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
view: canvas,
resolution: 1, // window.devicePixelRatio || 1,
// autoDensity: true,
backgroundColor: 0x6495ed,
backgroundColor: 0x47aba9,
resizeTo: window,
});
(window as any).__PIXI_APP__ = app;
Expand Down
14 changes: 7 additions & 7 deletions web/src/lib/render/colors.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {parseColorV4} from '$lib/webgl/color';

export const COLORS = [0x000000, 0xef476f, 0xffd166, 0x06d6a0, 0x118ab2, 0x118000, 0x000000];
export const COLORS = [0x000000, 0x00a4dd, 0xff6e71, 0x27d17c, 0xd3d66d, 0x9660c8, 0x3d3d3d];

export const COLORS_VEC4 = [
[0, 0, 0, 1],
parseColorV4('ef476f'),
parseColorV4('ffd166'),
parseColorV4('06d6a0'),
parseColorV4('118ab2'),
parseColorV4('118000'),
parseColorV4('000000'),
parseColorV4('00a4dd'),
parseColorV4('ff6e71'),
parseColorV4('27d17c'),
parseColorV4('d3d66d'),
parseColorV4('9660c8'),
parseColorV4('3d3d3d'),
];

0 comments on commit c8c11f3

Please sign in to comment.