Skip to content

Commit 8c06138

Browse files
committed
fixed areaEquals, added debug functionality
1 parent 43e2f67 commit 8c06138

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/bundles/robot_minigame/functions.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface RobotMap {
5454
areaLog: Area[]
5555
actionLog: Action[]
5656
message: string
57+
debugLog: string[]
5758
}
5859

5960
const state: RobotMap = {
@@ -65,7 +66,8 @@ const state: RobotMap = {
6566
areas: [],
6667
areaLog: [],
6768
actionLog: [],
68-
message: 'moved successfully'
69+
message: 'moved successfully',
70+
debugLog: []
6971
};
7072

7173
interface Robot extends Point {
@@ -438,7 +440,7 @@ export function entered_colors(
438440
const coloredAreas = state.areaLog
439441
.filter(area => colors.includes(area.flags.color)) // Filter relevant colors
440442
.filter(filterAdjacentDuplicateAreas); // Filter adjacent duplicates
441-
443+
442444
return coloredAreas.length === colors.length && coloredAreas.every(({ flags: { color } }, i) => color === colors[i]); // Check if each area has the expected color
443445
}
444446

@@ -762,7 +764,8 @@ function areaEquals(a: Area, b: Area) {
762764
a.vertices.length !== b.vertices.length // a and b must have an equal number of vertices
763765
|| a.vertices.some((v, i) => v.x !== b.vertices[i].x || v.y !== b.vertices[i].y) // a and b's vertices must be the same
764766
|| a.isObstacle !== b.isObstacle // Either both a and b or neither a nor b are obstacles
765-
|| Object.keys(a.flags).length === Object.length
767+
|| Object.keys(a.flags).length !== Object.keys(b.flags).length // Check flags length equality
768+
|| Object.keys(a.flags).some(key => a.flags[key] !== b.flags[key]) // Check flag value equality
766769
) return false;
767770

768771
return true;

src/tabs/RobotMaze/components/RobotSimulation.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React, { useEffect, useRef, useState } from 'react';
22
import type { Area, Action, PointWithRotation, RobotMap } from '../../../bundles/robot_minigame/functions';
3+
import { Properties } from '@blueprintjs/icons';
4+
import { State } from 'nbody';
35

46
/**
57
* Calculate the acute angle between 2 angles
@@ -134,7 +136,8 @@ const RobotSimulation : React.FC<MapProps> = ({
134136
message,
135137
// success,
136138
// messages,
137-
robotSize
139+
robotSize,
140+
debugLog
138141
}
139142
}) => {
140143
// Store animation status
@@ -155,6 +158,9 @@ const RobotSimulation : React.FC<MapProps> = ({
155158

156159
// Ensure canvas is preloaded correctly
157160
useEffect(() => {
161+
// DEBUG LOG REMOVE LATER
162+
console.log(debugLog);
163+
158164
// Only load if animationStatus is 0
159165
if (animationStatus !== 0) return;
160166

0 commit comments

Comments
 (0)