输入输出

程序输入格式
第一行代表棋子颜色1或是2
接下来15行每行15个数字代表了整个棋局0代表为空,1代表黑色棋子,2代表白色棋子
例子如下

  1. 2
  2. 2 0 0 0 0 1 0 0 0 2 0 1 2 1 2
  3. 0 0 0 1 0 0 0 0 0 0 2 1 2 2 2
  4. 0 2 0 0 1 1 0 0 0 0 0 0 2 2 1
  5. 1 2 1 0 0 1 0 0 2 0 1 0 1 0 0
  6. 2 0 2 1 1 0 0 0 0 1 0 0 0 1 1
  7. 2 0 1 0 2 2 0 0 0 0 0 0 0 0 2
  8. 0 1 0 0 2 2 1 0 0 0 0 0 1 2 1
  9. 0 1 1 1 2 1 0 0 2 0 0 0 2 2 1
  10. 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1
  11. 2 0 0 1 0 1 0 1 2 1 2 0 2 0 1
  12. 0 0 2 1 0 2 2 0 0 0 0 0 2 2 0
  13. 1 0 2 2 2 1 2 0 0 0 1 0 2 2 0
  14. 1 1 0 2 2 1 0 0 0 0 2 0 2 2 1
  15. 0 0 1 0 0 0 0 1 1 1 1 0 0 1 0
  16. 2 0 2 2 2 0 2 0 2 0 0 0 1 0 1

程序输出格式
程序输出两个数代表落子的行数和列数,数值范围是[1,15]
下面的例子表示程序落子再14行1列

  1. 14 1

参考代码

Python3 随机下棋参考代码

  1. import sys
  2. import random
  3. from typing import List
  4. def read() -> (int, List[List[int]]):
  5. f = sys.stdin.read()
  6. data = f.split()
  7. color_ = int(data[0])
  8. result_ = [[0 for j in range(0, 15)] for i in range(0, 15)]
  9. for i in range(0, 15):
  10. for j in range(0, 15):
  11. result_[i][j] = int(data[i * 15 + j + 1])
  12. return color_, result_
  13. if __name__ == '__main__':
  14. color, result = read()
  15. r = random.randint(0, 14)
  16. c = random.randint(0, 14)
  17. while result[r][c] != 0:
  18. r = random.randint(0, 14)
  19. c = random.randint(0, 14)
  20. print(r, c)

C++随机下棋参考代码

  1. #include <random>
  2. #include <iostream>
  3. using namespace std;
  4. int chessboard[15][15];
  5. int main() {
  6. mt19937 mt(199793);
  7. int color;
  8. cin >> color;
  9. for (auto &i : chessboard) {
  10. for (int &j : i) {
  11. cin >> j;
  12. }
  13. }
  14. while (true) {
  15. int r = mt() % 15;
  16. int c = mt() % 15;
  17. if (chessboard[r][c] == 0) {
  18. cout << r << " " << c;
  19. break;
  20. }
  21. }
  22. return 0;
  23. }

C语言随机下棋

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int chessboard[15][15];
  4. int main()
  5. {
  6. int color;
  7. scanf("%d", &color);
  8. srand(199793);
  9. for (int i = 0; i < 15; i++)
  10. {
  11. for (int j = 0; j < 15; j++)
  12. {
  13. scanf("%d", &chessboard[i][j]);
  14. }
  15. }
  16. int r = rand() % 15, c = rand() % 15;
  17. while (chessboard[r][c] != 0)
  18. {
  19. r = rand() % 15, c = rand() % 15;
  20. }
  21. printf("%d %d\n", r, c);
  22. }