From 15bd8b8ce2ebb920240b67280fa98644f4918225 Mon Sep 17 00:00:00 2001 From: EthanShin Date: Tue, 2 Jul 2019 23:45:10 +0900 Subject: [PATCH 1/3] feat: Add A_Chessboard_Game.kt description: Both players play a game in which the knight is moved in the (1,1) direction. It is a winning game if the opponent can not move anymore. --- .../kotlin/Game_Theory-A_Chessboard_Game.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Algorithms/kotlin/Game_Theory-A_Chessboard_Game.kt diff --git a/Algorithms/kotlin/Game_Theory-A_Chessboard_Game.kt b/Algorithms/kotlin/Game_Theory-A_Chessboard_Game.kt new file mode 100644 index 0000000..cbc4f66 --- /dev/null +++ b/Algorithms/kotlin/Game_Theory-A_Chessboard_Game.kt @@ -0,0 +1,23 @@ +import java.util.* +import kotlin.io.* +import kotlin.text.* + +fun chessboardGame(x: Int, y: Int): String { + + return "First" +} + +fun main(args: Array) { + val scan = Scanner(System.`in`) + + val t = scan.nextLine().trim().toInt() + + for (tItr in 1..t) { + val xy = scan.nextLine().split(" ") + val x = xy[0].trim().toInt() + val y = xy[1].trim().toInt() + + val result = chessboardGame(x, y) + println(result) + } +} \ No newline at end of file From 7e8a1f44d9f7ad1c71322d3572e8c53eb523135f Mon Sep 17 00:00:00 2001 From: EthanShin Date: Wed, 3 Jul 2019 23:45:26 +0900 Subject: [PATCH 2/3] feat: Modify A_Chessboard_Game.kt description: Both players play a game in which the knight is moved in the (1,1) direction. It is a winning game if the opponent can not move anymore. --- .../kotlin/Game_Theory-A_Chessboard_Game.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Algorithms/kotlin/Game_Theory-A_Chessboard_Game.kt b/Algorithms/kotlin/Game_Theory-A_Chessboard_Game.kt index cbc4f66..ad4a067 100644 --- a/Algorithms/kotlin/Game_Theory-A_Chessboard_Game.kt +++ b/Algorithms/kotlin/Game_Theory-A_Chessboard_Game.kt @@ -4,7 +4,20 @@ import kotlin.text.* fun chessboardGame(x: Int, y: Int): String { - return "First" + // 1. 좌표가 (1, 1)에서 부터 시작하기 때문에 (0, 0)으로 보정하기 위해 1을 빼준다. + /* + 2. 아래와 같은 패턴이 반복되므로, 4로 나눈 나머지를 이용한다. + S S F F + S S F F + F F F F + F F F F + */ + val _x = (x - 1) % 4 + val _y = (y - 1) % 4 + + // 3. 좌표값 (0,0), (0,1), (1,0), (1,1) 일 때, Player2가 이긴다. + return if ((_x < 2) and (_y < 2)) "Second" + else "First" } fun main(args: Array) { From 21aa6e867c4d9deaaf821962b40f171c97e30399 Mon Sep 17 00:00:00 2001 From: EthanShin Date: Wed, 3 Jul 2019 23:47:49 +0900 Subject: [PATCH 3/3] docs: Modify REMOTE_README.md resolved: #110 description: Add a file name to the index. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 67b0323..c96db03 100644 --- a/README.md +++ b/README.md @@ -83,5 +83,6 @@ All about hackerrank - Bit_Manipulation-Lonely_Integer.kt - Bit_Manipulation-Maximizing_XOR.kt - Bit_Manipulation-Sum_vs_XOR.kt +- Game_Theory-A_Chessboard_Game.kt - Game_Theory-Game_of_Stones.kt - Game_Theory-Tower_Breakers.kt \ No newline at end of file