Tron Racers
Loading...
+ Нов въпрос
silvana1303 avatar silvana1303 4 Точки

02. Tron Racers from C# Advanced Exam - 24 Feb 2019

Каквото и да правя, стринга, с който трябва да попълня матрицата ми дава нул, не разбирам къде греша!

кода ми: https://pastebin.com/MVE78wn6

Tron Racers

The new TRON tournament has started and you have to keep track of the players on the field.

You will be given an integer n for the size of the matrix. On the next n lines, you will receive the rows of the matrix. The game starts with two players (first player is marked with "f" and the second player is marked with "s") in random positions and all of the empty slots will be filled with "*".

Each turn you will be given commands respectively for each player’s movement. The first command is for the first player and the second is for the second player. After a player moves, he leaves a trail on the field. The symbol that marks the trail is the same as the player's symbol. If a player goes out of the matrix, he comes in from the other side. For example, if the player is on 0, 0 and the next command is left, he goes to the last spot in the first row.

If a player steps on the other player's trail, he dies. When a player dies in the field, you should write "x" in the position where he died.

When only one of the players is left alive on the field the game ends.

Input

  • On the first line, you are given the integer N – the size of the square matrix.
  • The next N lines holds the values for every row.
  • On each of the next lines you will get two commands separated by space       .

Output

  • In the end print the matrix.

Constraints

  • The size of the matrix will be between [2…20].
  • There will always be exactly two players.
  • The players will always be indicated with "f" for the first one and "s" for the second one.
  • There will always be enough commands to finish the game with one player alive.
  • There will not be commands where a player goes back and steps on his trail from the previous turn.
  • Commands will be in the format up, down, left or right.

Examples

Input

Output

Comments

5

***f*

**s**

*****

*****

*****

down down

right down

down right

down down

down left

left left

***f*

**sff

**s*f

**ssf

**sxf

The first command is down down so f moves down and s moves down. After each turn the field is:

  1      2      3      4      5      6

***f*  ***f*  ***f*  ***f*  ***f*  ***f*

**sf*  **sff  **sff  **sff  **sff  **sff

**s**  **s**  **s*f  **s*f  **s*f  **s*f

*****  **s**  **ss*  **ssf  **ssf  **ssf

*****  *****  *****  ***s*  **ssf  **sxf

On turn 6 f crashes into s's trail and f dies. As there is only one player left alive s is the only one left he is the winner.

4

*f**

****

**s*

****

down up

down right

right right

*f**

*fss

*fx*

****

 

 

 

 

Тагове:
0
C# Advanced
georgi.d.gradev avatar georgi.d.gradev 47 Точки
Best Answer

Привет отново smiley

При валидацията на командата за движение на втория играч използваш данните за първия играч;

if (matrix[firstRow, firstCol] != 'f')
     {
         matrix[firstRow, firstCol] = 's';
      }
 else
     {
     matrix[firstRow, firstCol] = 'x';
      break;
  } 

Промени го на :

if (matrix[secondRow, secondCol] != 'f')
     {
         matrix[secondRow, secondCol] = 's';
      }
 else
     {
     matrix[secondRow, secondCol] = 'x';
      break;
  } 

 

От ред 132 до ред 140.

 

Успех утре на изпита yes

0
24/10/2020 18:01:21
silvana1303 avatar silvana1303 4 Точки

Много благодаря, цял ден ме спасявате! Успех и на вас

1