Advertisement
3vo

Battle

3vo
Apr 5th, 2023
699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. let input = [
  3.     // "2 2",
  4.     // "0 1",
  5.     // "1 1",
  6.     // "1 0",
  7.     // "1 1",
  8.     // "Shoot 1 1",
  9.     // "Shoot 0 1",
  10.     // "Shoot 0 0",
  11.     // "Shoot 0 0",
  12.     // "Shoot 1 1",
  13.     // "Shoot 1 0",
  14.     // "END",
  15.  
  16.         "3 4",
  17.         "0 1 1 1",
  18.         "1 1 0 0",
  19.         "1 1 0 1",
  20.         "1 0 1 1",
  21.         "1 0 0 0",
  22.         "1 1 1 1",
  23.         "Shoot 2 3",
  24.         "Shoot 1 1",
  25.         "Shoot 2 1",
  26.         "Shoot 0 0",
  27.         "Shoot 1 1",
  28.         "Shoot 1 1",
  29.         "Shoot 2 1",
  30.         "Shoot 2 3",
  31.         "END",
  32.  
  33. ];
  34.  
  35. let print = this.print || console.log;
  36. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  37.  
  38.  
  39. let matrixSize = gets().split(" ");
  40. let row = +matrixSize[0];
  41. let column = +matrixSize[1];
  42.  
  43. // let board1 = Array(matrixSize).fill(null).map(() => Array(num).fill(0));
  44. // let board2 = Array(matrixSize).fill(null).map(() => Array(num).fill(0));
  45.  
  46. let board1 = [];
  47. let board2 = [];
  48.  
  49. //first player board
  50. for (let i = 0; i < row; i++) {
  51.     let currentArr = gets().split(" ");
  52.     board1.push(currentArr);
  53. }
  54.  
  55. //2nd player board
  56.  
  57. for (let i = 0; i < row; i++) {
  58.     let currentArr = gets().split(" ");
  59.     let reveseArr = currentArr.reverse();
  60.     board2.unshift(reveseArr);
  61. }
  62.  
  63. //shooting
  64.  
  65. let currentPlayer = 1;
  66. let command = gets().split(" ");
  67.  
  68. // console.log(command);
  69. // let x = command[1];
  70. // console.log(x);
  71. // let y = command[2];
  72. let resultOfShooting = "";
  73.  
  74. while (command[0] != "END") {
  75.  
  76.  
  77.     let x = command[1];
  78.     let y = command[2];
  79.  
  80.     if (currentPlayer % 2 == 0) { //2nd player shoots
  81.         resultOfShooting = board1[x][y];
  82.         board1[x][y] = 'X'
  83.     } else { //1st player shoots
  84.         resultOfShooting = board2[x][y];
  85.         board2[x][y] = 'X'
  86.     }
  87.  
  88.     if (resultOfShooting == '1') {
  89.         print('Booom')
  90.     } else if (resultOfShooting == '0') {
  91.         print('Missed')
  92.     } else if (resultOfShooting == 'X') {
  93.         print('You already shot there!')
  94.     }
  95.     currentPlayer++;
  96.  
  97.     command = gets().split(" ");
  98.     // console.table(board1);
  99.     // console.table(board2);
  100.  
  101. }
  102. //count points:
  103. let player1points = 0;
  104. let player2points = 0;
  105. let currentPosition1player = "";
  106. let currentPosition2player = "";
  107.  
  108. for (let i = 0; i < row; i++) {
  109.     for (let j = 0; j < column; j++) {
  110.         currentPosition1player = board1[i][j];
  111.         currentPosition2player = board2[i][j];
  112.  
  113.         if (currentPosition1player == 1){
  114.             player1points++;
  115.         }
  116.         if (currentPosition2player == 1){
  117.             player2points++;
  118.         }
  119.     }
  120. }
  121.  
  122. print(`${player1points}:${player2points}`);
  123. // console.table(board1);
  124. // console.table(board2);
  125.  
  126.  
  127.  
Tags: A49
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement