Skip to content

Commit

Permalink
Add line-of-sight restriction on ranged combat!
Browse files Browse the repository at this point in the history
  • Loading branch information
xpmatteo committed Oct 28, 2023
1 parent ed7e63f commit a3ad37d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lib/hexlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions test/lib/hexlib_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down

0 comments on commit a3ad37d

Please sign in to comment.