From bba3ac306733dbc81a72af347f1e9770e62422d0 Mon Sep 17 00:00:00 2001 From: Ari Trachtenberg Date: Wed, 2 Oct 2024 00:03:46 -0400 Subject: [PATCH 1/2] add getBoardSquare --- ttt_interface/ttt.cpp | 6 ++++++ ttt_interface/ttt.h | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ttt_interface/ttt.cpp b/ttt_interface/ttt.cpp index 9a82d31..697c07a 100644 --- a/ttt_interface/ttt.cpp +++ b/ttt_interface/ttt.cpp @@ -204,6 +204,12 @@ string getBoard(GAME_CODE theGameCode) { return parseGameStatus(theGameCode)["board"]; } +SQUARE getBoardSquare(string board, int theRow, int theCol) { + int cols = board.find("\n"); + return board[theRow*(cols+1)+theCol]; +} + + SQUARE getHasWon(GAME_CODE theGameCode) { return parseGameStatus(theGameCode)["hasWon"][0]; } diff --git a/ttt_interface/ttt.h b/ttt_interface/ttt.h index c326b70..562e81c 100644 --- a/ttt_interface/ttt.h +++ b/ttt_interface/ttt.h @@ -97,10 +97,18 @@ SQUARE getToMove(GAME_CODE theGameCode); /** * @param theGameCode The code of the Game in question. - * @return A tstring representing the current board in the game with the given game code. + * @return A string representing the current board in the game with the given game code. */ string getBoard(GAME_CODE theGameCode); +/** + * @param board a game board produced by the function getBoard(GAME_CODE theGameCode). + * @param theRow a row on the game board. + * @param theCol a colum on the game board. + * @return The square at row [theRow] and column [theCol] on the given board. + */ +SQUARE getBoardSquare(string board, int theRow, int theCol); + /** * @param theGameCode The code of the Game in question. * @return Who has won the game, or '-' if no one has won yet. -- GitLab From 21da515bd5e299d21f3f6c127fec4fc4fff2b612 Mon Sep 17 00:00:00 2001 From: Ari Trachtenberg Date: Wed, 2 Oct 2024 00:31:07 -0400 Subject: [PATCH 2/2] add getBoardSquare --- ttt_interface/ttt.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ttt_interface/ttt.cpp b/ttt_interface/ttt.cpp index 697c07a..9585fa1 100644 --- a/ttt_interface/ttt.cpp +++ b/ttt_interface/ttt.cpp @@ -193,7 +193,7 @@ string makeMove(GAME_CODE theGameCode, PLAYER_CODE thePlayerCode, SQUARE theSide } int getRows(GAME_CODE theGameCode) { - return strToInt(parseGameStatus(theGameCode)["rows"]); + return strToInt(parseGameStatus(theGameCode)["rows"]); } int getCols(GAME_CODE theGameCode) { @@ -205,8 +205,8 @@ string getBoard(GAME_CODE theGameCode) { } SQUARE getBoardSquare(string board, int theRow, int theCol) { - int cols = board.find("\n"); - return board[theRow*(cols+1)+theCol]; + int cols = board.find("\\n"); + return board[theRow*(cols+2)+theCol]; } -- GitLab