Quarto Challenge

quarto-challenge

Quatro is a 2 player game invented by Blaies Müller.

It is played on a 4 X 4 board with 16 pieces each of which is either

Red or Blue
Short or Tall
Hollow or Solid
Circular or Square
The game begins with one player choosing the piece and the other placing it on the board. A player wins by placing 4 pieces on the board horizontally, vertically or diagonally all of which have a common attribute ( red or tall or hollow etc ).

In this game, each of the 16 pieces are represented using 4 bits.

Red or Blue ( 0 or 1 respectively forming the most significant bit )
Short or Tall ( 0 or 1 respectively forming the 3rd bit )
Hollow or Solid ( 0 or 1 respectively forming the 2nd bit )
Circular or Square ( 0 or 1 respectively forming the least significant bit )
So, a Red Tall Hollow Circular piece is represented by ( 0100 = 4 )

Input Format
The first line of the input contains the player id 1 or 2. The second line of the input is a string PICK or PLACE indicating whether a player has to pick a piece or place an already picked piece on the board. 4 lines follow, each line containing 4 space separated integers ( -1 indicating an empty slot on the board and a positive number indicating a piece ).
Next line contains N, total number of pieces left to be placed on the board.
N lines follow each line containing the decimal representation of the piece.
An optional next line contains an integer indicating the piece to be placed on the board if the move is PLACE.

Board is indexed according to Matrix Convention

Output Format

If the input is PICK, out of the available pieces, pick one to be placed by our opponent on the board and print its number to STDOUT.
If the input is PLACE, print 2 space separated integers indicating the row and column where the piece has to be placed.

Sample Input #00

2
PICK
-1 -1 1 -1
-1 -1 -1 -1
10 0 14 15
9 -1 -1 12
9
2
3
4
5
6
7
8
11
13
Sample Output #00

7
Explanation #00

Here, the 2nd player on receiving the input, PICKs 7 ( Red Tall Hollow Circular ) piece to be placed on the board whose position is decided by the opponent.

Sample Input #01

1
PLACE
-1 -1 1 -1
-1 -1 -1 -1
10 0 14 15
9 -1 -1 12
8
2
3
4
5
6
8
11
13
7
Sample Output #01

1 1
Explanation #01

On receiving this input, the 1st player decides to place 7 ( the last integer in input ) at the position 1 1.

Sample Input #02

2
PLACE
2 -1 1 -1
-1 -1 -1 -1
10 0 14 15
9 -1 -1 12
7
4
5
6
7
8
11
13
3
Sample Output #02
1 0
Explanation #02

After placing 3 at 1 0, the 2nd player wins the game as

2 3 10 9 ( the first column ) all share the same 2nd most significant bit which is 0.

0010 0011 1010 1001

as you can see, the 2nd most significant bit is all 0 and therefore, all the pieces have the common attribute of being SHORT.

  • > Submit your code down below
Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
progressive-reactivity-with-ngrx/store-and-ngxs

Progressive Reactivity with NgRx/Store and NGXS

Next Post
16-educational-podcasts-for-minority-entrepreneurs

16 Educational Podcasts for Minority Entrepreneurs

Related Posts

AI治理最重要的能力:缺乏证据支持时懂得暂停

1)观点先行(P0) 一句话观点: 在 AI 协作里,最有价值的治理能力不是“更快修完”,而是“证据不够时敢停下,并把缺什么证据说清楚”。 2)治理背景(P1) 复杂系统里的真实问题,不是没人干活,而是大家都在干活,却很难判断到底有没有真的完成。 AI 参与后,这个问题会更明显: AI 很容易给出“看起来已经完成”的答案。 多个智能体并行提交回执,信息会很快变成噪音。 模块测试通过,常常被误读成系统已经恢复。 本地治理体系之所以更快,不是因为流程更短,而是因为它把“没完成”这件事制度化了: 可以停在中间状态。 可以明确写出阻断原因。 可以等证据补齐后再推进状态。 3)信号提取(P0)…
Read More