From 7045262c97f15477efa9a7c1f87f9dcc06feebd0 Mon Sep 17 00:00:00 2001 From: yokomaru Date: Sun, 25 Feb 2024 21:11:19 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20put=5Fstone,=20turn,=20placeable=3F?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/reversi_methods.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/reversi_methods.rb b/lib/reversi_methods.rb index e450fa1..d6e075f 100644 --- a/lib/reversi_methods.rb +++ b/lib/reversi_methods.rb @@ -47,7 +47,7 @@ def put_stone(board, cell_ref, stone_color, dry_run: false) # コピーした盤面にて石の配置を試みて、成功すれば反映する copied_board = Marshal.load(Marshal.dump(board)) - copied_board[pos.col][pos.row] = stone_color + copied_board[pos.row][pos.col] = stone_color turn_succeed = false Position::DIRECTIONS.each do |direction| @@ -63,6 +63,7 @@ def put_stone(board, cell_ref, stone_color, dry_run: false) def turn(board, target_pos, attack_stone_color, direction) return false if target_pos.out_of_board? return false if target_pos.stone_color(board) == attack_stone_color + return false if target_pos.stone_color(board) == BLANK_CELL next_pos = target_pos.next_position(direction) if (next_pos.stone_color(board) == attack_stone_color) || turn(board, next_pos, attack_stone_color, direction) @@ -86,6 +87,7 @@ def placeable?(board, attack_stone_color) return true if put_stone(board, position.to_cell_ref, attack_stone_color, dry_run: true) end end + false end def count_stone(board, stone_color) From 7cde50b61d38e38d4cf86f0b39fca08527277e6d Mon Sep 17 00:00:00 2001 From: yokomaru Date: Sun, 25 Feb 2024 21:19:26 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20target=5Fpos.stone=5Fcolor(board)=20?= =?UTF-8?q?=3D=3D=20BLANK=5FCELL=E3=82=92||=20=E3=81=A7=E6=9B=B8=E3=81=8D?= =?UTF-8?q?=E6=8F=9B=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/reversi_methods.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/reversi_methods.rb b/lib/reversi_methods.rb index d6e075f..97ebb05 100644 --- a/lib/reversi_methods.rb +++ b/lib/reversi_methods.rb @@ -62,8 +62,7 @@ def put_stone(board, cell_ref, stone_color, dry_run: false) def turn(board, target_pos, attack_stone_color, direction) return false if target_pos.out_of_board? - return false if target_pos.stone_color(board) == attack_stone_color - return false if target_pos.stone_color(board) == BLANK_CELL + return false if target_pos.stone_color(board) == attack_stone_color || target_pos.stone_color(board) == BLANK_CELL next_pos = target_pos.next_position(direction) if (next_pos.stone_color(board) == attack_stone_color) || turn(board, next_pos, attack_stone_color, direction) From fb8a034ed0a48f8eda7ac6fc47cf2b8807b71900 Mon Sep 17 00:00:00 2001 From: yokomaru Date: Sun, 10 Mar 2024 22:31:23 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=20target=5Fpos.out=5Fof=5Fboard=3F?= =?UTF-8?q?=20=E3=82=82=E3=81=BE=E3=81=A8=E3=82=81=E3=81=A6if=20=E6=96=87?= =?UTF-8?q?=E3=81=AB=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/reversi_methods.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/reversi_methods.rb b/lib/reversi_methods.rb index 97ebb05..469f288 100644 --- a/lib/reversi_methods.rb +++ b/lib/reversi_methods.rb @@ -61,8 +61,9 @@ def put_stone(board, cell_ref, stone_color, dry_run: false) end def turn(board, target_pos, attack_stone_color, direction) - return false if target_pos.out_of_board? - return false if target_pos.stone_color(board) == attack_stone_color || target_pos.stone_color(board) == BLANK_CELL + if target_pos.out_of_board? || target_pos.stone_color(board) == attack_stone_color || target_pos.stone_color(board) == BLANK_CELL + return false + end next_pos = target_pos.next_position(direction) if (next_pos.stone_color(board) == attack_stone_color) || turn(board, next_pos, attack_stone_color, direction)