Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let input = [
- // "2 2",
- // "0 1",
- // "1 1",
- // "1 0",
- // "1 1",
- // "Shoot 1 1",
- // "Shoot 0 1",
- // "Shoot 0 0",
- // "Shoot 0 0",
- // "Shoot 1 1",
- // "Shoot 1 0",
- // "END",
- "3 4",
- "0 1 1 1",
- "1 1 0 0",
- "1 1 0 1",
- "1 0 1 1",
- "1 0 0 0",
- "1 1 1 1",
- "Shoot 2 3",
- "Shoot 1 1",
- "Shoot 2 1",
- "Shoot 0 0",
- "Shoot 1 1",
- "Shoot 1 1",
- "Shoot 2 1",
- "Shoot 2 3",
- "END",
- ];
- let print = this.print || console.log;
- let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- let matrixSize = gets().split(" ");
- let row = +matrixSize[0];
- let column = +matrixSize[1];
- // let board1 = Array(matrixSize).fill(null).map(() => Array(num).fill(0));
- // let board2 = Array(matrixSize).fill(null).map(() => Array(num).fill(0));
- let board1 = [];
- let board2 = [];
- //first player board
- for (let i = 0; i < row; i++) {
- let currentArr = gets().split(" ");
- board1.push(currentArr);
- }
- //2nd player board
- for (let i = 0; i < row; i++) {
- let currentArr = gets().split(" ");
- let reveseArr = currentArr.reverse();
- board2.unshift(reveseArr);
- }
- //shooting
- let currentPlayer = 1;
- let command = gets().split(" ");
- // console.log(command);
- // let x = command[1];
- // console.log(x);
- // let y = command[2];
- let resultOfShooting = "";
- while (command[0] != "END") {
- let x = command[1];
- let y = command[2];
- if (currentPlayer % 2 == 0) { //2nd player shoots
- resultOfShooting = board1[x][y];
- board1[x][y] = 'X'
- } else { //1st player shoots
- resultOfShooting = board2[x][y];
- board2[x][y] = 'X'
- }
- if (resultOfShooting == '1') {
- print('Booom')
- } else if (resultOfShooting == '0') {
- print('Missed')
- } else if (resultOfShooting == 'X') {
- print('You already shot there!')
- }
- currentPlayer++;
- command = gets().split(" ");
- // console.table(board1);
- // console.table(board2);
- }
- //count points:
- let player1points = 0;
- let player2points = 0;
- let currentPosition1player = "";
- let currentPosition2player = "";
- for (let i = 0; i < row; i++) {
- for (let j = 0; j < column; j++) {
- currentPosition1player = board1[i][j];
- currentPosition2player = board2[i][j];
- if (currentPosition1player == 1){
- player1points++;
- }
- if (currentPosition2player == 1){
- player2points++;
- }
- }
- }
- print(`${player1points}:${player2points}`);
- // console.table(board1);
- // console.table(board2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement