174. 棋類小遊戲

I'm a slow walker, but I never walk backwards.

Task Description

君平最近對暗棋非常感興趣,因此想模仿暗棋設計一個棋類小遊戲,詳細介紹如下:
此遊戲為雙人遊戲,兩位玩家分別為「奇數方」和「偶數方」。 棋盤大小是4*4。 棋子共有16顆,棋子編號從0到15。奇數方的棋子編號為1, 3, 5, ..., 15;偶數方的棋子編號為0, 2, 4, ..., 14。 棋盤上會擺放若干棋子,有棋子的位置會標示棋子編號,如果一個位置是空的,則以-1表示。

吃子規則與棋子Level表如下 :

  1. 只可吃相鄰棋子
  2. 相同Level的棋子可以互吃
  3. 在Level 1到7之間的棋子,Level大的棋子可吃Level小的棋子
  4. Level 7的棋子不能吃Level 0的棋子
  5. Level 0的棋子可以吃Level 7的棋子
Level 0 1 2 3 4 5 6 7
棋子編號 0, 1 2, 3 4, 5 6, 7 8, 9 10, 11 12, 13 14, 15

請幫君平找出盤面可吃敵方所有走步方法。

Hint

Capture.h

打上 function header 以及相關的設定。

void CaptureOppPieces(int board[4][4], int turn);

Capture.c

撰寫程式碼後對應上傳。

#include "Capture.h"
void CaptureOppPieces(int board[4][4], int turn) {
    /* add your code */
}

main.c

這個檔案無法更改也無須上傳。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
#include "Capture.h"
 
int main() {
    int board[4][4], turn;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            scanf("%d", &board[i][j]);
        }
    }
    scanf("%d", &turn);
 
    CaptureOppPieces(board, turn);
 
}

Input Format

前四列輸入4*4盤面棋子分布與空白位置。 第五列輸入1或0,分別表示君平 (我方) 是奇數方或偶數方。

Output Format

請印出敵方棋子被我方棋子吃掉的所有組合。
按照敵方棋子的 Level 由大到小;如果敵方棋子的 Level 相同,則按照我方棋子的 Level 由大到小印出吃子組合。

Sample Input

14 15 12 13
 1  0 -1 -1
-1 -1 10  8
11  6  7  4
0

Sample Output

15 is captured by 14
15 is captured by 0
13 is captured by 12
7 is captured by 10
7 is captured by 6
1 is captured by 0

Sample Input

14 15 12 13
 1  0 -1 -1
-1 -1 10  8
11  6  7  4
1

Sample Output

14 is captured by 15
14 is captured by 1
12 is captured by 15
12 is captured by 13
6 is captured by 11
6 is captured by 7
4 is captured by 7
0 is captured by 1

Submit

Login

Testdata Set

Download Testdata