From a3ad37d9ef14f4611a3c271b06fa26d6d3e266b1 Mon Sep 17 00:00:00 2001 From: Matteo Vaccari Date: Sat, 28 Oct 2023 09:40:14 +0200 Subject: [PATCH] Add line-of-sight restriction on ranged combat! --- README.md | 2 +- src/lib/hexlib.js | 2 +- test/lib/hexlib_test.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8ddf45c..6fc5b8f 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ image to appear. The parameters are: # TODO AI - macro-move sampling: avoid duplicate macro-moves in a node's children +- macro-move sampling: make units not moving an option - macro-move sampling: tune the explore/exploit ratio - open loop instead of chance nodes - implement evasion and line-of-sight rules for ranged combat, to allow the realistic game strategy to emerge @@ -60,7 +61,6 @@ image to appear. The parameters are: # TODO RULES - evasion -- ranged combat line of sight restriction - more cards - advance after combat - cavalry, chariot battle again after advance diff --git a/src/lib/hexlib.js b/src/lib/hexlib.js index 8ec4b3d..d0f2aa4 100644 --- a/src/lib/hexlib.js +++ b/src/lib/hexlib.js @@ -194,7 +194,7 @@ export function hasLineOfSight(toHex, fromHex, isBlocked = () => false) { const distance = fromHex.distance(toHex); const step = hex_subtract(toHex, fromHex); const stepSize = 1.0 / distance; - for (let i = 0; i < distance; i++) { + for (let i = 1; i < distance; i++) { const stepHex = hex_round(fromHex.q + (step.q * stepSize * i), fromHex.r + (step.r * stepSize * i), fromHex.s + (step.s * stepSize * i)); diff --git a/test/lib/hexlib_test.js b/test/lib/hexlib_test.js index 23d4c33..e4603b1 100644 --- a/test/lib/hexlib_test.js +++ b/test/lib/hexlib_test.js @@ -61,8 +61,8 @@ describe('line of sight', () => { {from: hexOf(0,0), to: hexOf(-1,2), expected: true }, ].forEach(({from, to, expected}) => { test(`Line of sight from ${from} to ${to}: ${expected}`, () => { - console.log(`Line of sight from ${from} to ${to}: ${expected}`) - expect(hasLineOfSight(to, from)).toBe(expected); + const blocked = hex => hex === from || hex === to; + expect(hasLineOfSight(to, from)).toBe(expected); }); });