14282 - After the Gomoku Battle   

Description

 

 

After playing Gomoku for a whole day, Doraemon and Capoo are looking to try new games.They are interested in exploring other classic board games, such as Tic-tac-toe and Connect4, which share the "n-in-a-row" style with Gomoku. Your mission is to develop a program that supports the games of Tic-tac-toe and Connect4 for them to play.

  • Tic-tac-toe (https://en.wikipedia.org/wiki/Tic-tac-toe)
    • The goal is to be the first to get three of your marks in a row (horizontally, vertically, or diagonally).
    • Players take turns placing their symbol (either X or O) in an empty square on a 3x3 grid. 
    • The first player to align three of their symbols in a row on the grid wins the game.
    • If all nine squares are filled and no player has three marks in a row, the game is a draw.
    • In this problem, the first player uses "O" and places their symbol first, followed by the second player who uses "X".
  • Connect4 (https://en.wikipedia.org/wiki/Connect_Four)
    • The goal is to be the first to form a horizontal, vertical, or diagonal line of four of one's own discs.
    • Players alternate turns dropping colored discs from the top into a 7-column, 6-row vertically suspended grid, the pieces fall straight down, occupying the lowest available space within the column.
    • The first player to get four of their discs in a row (horizontally, vertically, or diagonally) wins the game.
    • If the board is filled completely without any player forming a line of four, the game ends in a draw.
    • In this problem, the first player uses "W" discs and goes first, followed by the second player who uses "B" discs.

This is a partial judge problem. Please review the provided code and refer to the sections labeled "TODO" in the function.h file for further details, and using C++17 to submit your solution.

 

Input

The first line of the input contains an integer N, representing the number of test cases. (1 ≤ N ≤ 100)

Each of the following N lines represents a test case. Each line records a game session, detailing every move made by the players. The game may conclude early if one player wins. The game records are formatted as follows:

<TicTacToe/ConnectFour> <Player1_Name>:<Move> <Player2_Name>:<Move> <Player1_Name>:<Move> ...

We guarantee that players will not play out of turn or make illegal moves, such as placing pieces on already occupied spaces.

The move format for Tic-tac-toe is x/y where "x" represents the row and "y" represents the column, indicating the placement of a piece on the board at position board[x][y]; The move format for Connect4 is cx where "x" represents the column in which the disk is dropped.

 

Output

Refer to the sample output provided.

If a game concludes without a winner after all moves in each testcase, output "Tie". Otherwise, tell the winner of the game. Additionally, display the status of the board at the end of the game. Please ensure to leave an empty line in the output at the end of each test case.

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

14282.cpp

Partial Judge Header

14282.h


Discuss