From ce43a7e11f7d69427fb397c14b332e96ab47cef8 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 19 Jun 2021 22:17:16 +0200 Subject: crusader: optimize muster checks --- rules.js | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/rules.js b/rules.js index 5b2d4d1..4cc8f8a 100644 --- a/rules.js +++ b/rules.js @@ -437,12 +437,8 @@ function can_block_muster_with_3_moves(n0, muster) { if (can_block_use_road_to_muster(n1, n2)) { if (n2 == muster) return true; - for (let n3 of TOWNS[n2].exits) { - if (can_block_use_road_to_muster(n2, n3)) { - if (n3 == muster) - return true; - } - } + if (TOWNS[n2].exits.includes(muster)) + return can_block_use_road_to_muster(n2, muster); } } } @@ -455,24 +451,16 @@ function can_block_muster_with_2_moves(n0, muster) { if (can_block_use_road_to_muster(n0, n1)) { if (n1 == muster) return true; - for (let n2 of TOWNS[n1].exits) { - if (can_block_use_road_to_muster(n1, n2)) { - if (n2 == muster) - return true; - } - } + if (TOWNS[n1].exits.includes(muster)) + return can_block_use_road_to_muster(n1, muster); } } return false; } function can_block_muster_with_1_move(n0, muster) { - for (let n1 of TOWNS[n0].exits) { - if (can_block_use_road_to_muster(n0, n1)) { - if (n1 == muster) - return true; - } - } + if (TOWNS[n0].exits.includes(muster)) + return can_block_use_road_to_muster(n0, muster); return false; } -- cgit v1.2.3