Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Tron3D
- {
- public enum Direction
- {
- Up,
- Down,
- Right,
- Left
- }
- public class Player
- {
- public int currentRow { get; set; }
- public int currentCol { get; set; }
- public int nextRow { get; set; }
- public int nextCol { get; set; }
- public Direction currentDirection { get; set; }
- public bool loose = false;
- public string movesCollection { get; set; }
- public bool Loose
- {
- get
- {
- return this.loose;
- }
- set
- {
- this.loose = value;
- }
- }
- }
- class Tron3D
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- string[] dims = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- int[] dimensions = new int[3];
- for (int i = 0; i < dimensions.Length; i++)
- {
- dimensions[i] = int.Parse(dims[i]);
- }
- int x = dimensions[0];
- int y = dimensions[1];
- int z = dimensions[2];
- string[,] matrix = new string[x + 1,(y + z + y + z)];
- Player redPlayer = new Player();
- Player bluePlayer = new Player();
- redPlayer.movesCollection = Console.ReadLine();
- bluePlayer.movesCollection = Console.ReadLine();
- redPlayer.currentRow = (x / 2);
- redPlayer.currentCol = y / 2;
- redPlayer.currentDirection = Direction.Right;
- redPlayer.nextRow = redPlayer.currentRow;
- redPlayer.nextCol = redPlayer.currentCol+1;
- matrix[redPlayer.currentRow,redPlayer.currentCol] = "used";
- bluePlayer.currentRow = x / 2;
- bluePlayer.currentCol = y+z+y/2;
- bluePlayer.currentDirection = Direction.Left;
- bluePlayer.nextRow = bluePlayer.currentRow;
- bluePlayer.nextCol = bluePlayer.currentCol-1;
- matrix[bluePlayer.currentRow, bluePlayer.currentCol] = "used";
- int redPlayerIndexStart = 0;
- int bluePlayerIndexStart = 0;
- while (true)
- {
- //red player
- #region
- for (int i = redPlayerIndexStart; i < redPlayer.movesCollection.Length; i++)
- {
- if (redPlayer.movesCollection[i] == 'L')
- {
- if (redPlayer.currentDirection == Direction.Up)
- {
- redPlayer.nextRow--;
- redPlayer.nextCol--;
- redPlayer.currentDirection = Direction.Left;
- }
- else if (redPlayer.currentDirection == Direction.Down)
- {
- redPlayer.nextRow++;
- redPlayer.nextCol++;
- redPlayer.currentDirection = Direction.Right;
- }
- else if (redPlayer.currentDirection == Direction.Right)
- {
- redPlayer.nextRow++;
- redPlayer.nextCol--;
- redPlayer.currentDirection = Direction.Up;
- }
- else if (redPlayer.currentDirection == Direction.Left)
- {
- redPlayer.nextRow--;
- redPlayer.nextCol++;
- redPlayer.currentDirection = Direction.Down;
- }
- }
- else if (redPlayer.movesCollection[i] == 'R')
- {
- if (redPlayer.currentDirection == Direction.Up)
- {
- redPlayer.nextRow--;
- redPlayer.nextCol++;
- redPlayer.currentDirection = Direction.Right;
- }
- else if (redPlayer.currentDirection == Direction.Down)
- {
- redPlayer.nextRow++;
- redPlayer.nextCol--;
- redPlayer.currentDirection = Direction.Left;
- }
- else if (redPlayer.currentDirection == Direction.Right)
- {
- redPlayer.nextRow--;
- redPlayer.nextCol--;
- redPlayer.currentDirection = Direction.Down;
- }
- else if (redPlayer.currentDirection == Direction.Left)
- {
- redPlayer.nextRow++;
- redPlayer.nextCol++;
- redPlayer.currentDirection = Direction.Up;
- }
- }
- else if (redPlayer.movesCollection[i] == 'M')
- {
- redPlayer.currentRow = redPlayer.nextRow;
- redPlayer.currentCol = redPlayer.nextCol;
- if (redPlayer.currentDirection == Direction.Up)
- {
- redPlayer.nextRow++;
- }
- else if (redPlayer.currentDirection == Direction.Down)
- {
- redPlayer.nextRow--;
- }
- else if (redPlayer.currentDirection == Direction.Right)
- {
- redPlayer.nextCol++;
- }
- else if (redPlayer.currentDirection == Direction.Left)
- {
- redPlayer.nextCol--;
- }
- // if we hit M then we continue
- redPlayerIndexStart = i + 1;
- break;
- }
- }
- #endregion
- //blue player
- #region
- for (int i = bluePlayerIndexStart; i < bluePlayer.movesCollection.Length; i++)
- {
- if (bluePlayer.movesCollection[i] == 'L')
- {
- if (bluePlayer.currentDirection == Direction.Up)
- {
- bluePlayer.nextRow--;
- bluePlayer.nextCol--;
- bluePlayer.currentDirection = Direction.Left;
- }
- else if (bluePlayer.currentDirection == Direction.Down)
- {
- bluePlayer.nextRow++;
- bluePlayer.nextCol++;
- bluePlayer.currentDirection = Direction.Right;
- }
- else if (bluePlayer.currentDirection == Direction.Right)
- {
- bluePlayer.nextRow++;
- bluePlayer.nextCol--;
- bluePlayer.currentDirection = Direction.Up;
- }
- else if (bluePlayer.currentDirection == Direction.Left)
- {
- bluePlayer.nextRow--;
- bluePlayer.nextCol++;
- bluePlayer.currentDirection = Direction.Down;
- }
- }
- else if (bluePlayer.movesCollection[i] == 'R')
- {
- if (bluePlayer.currentDirection == Direction.Up)
- {
- bluePlayer.nextRow--;
- bluePlayer.nextCol++;
- bluePlayer.currentDirection = Direction.Right;
- }
- else if (bluePlayer.currentDirection == Direction.Down)
- {
- bluePlayer.nextRow++;
- bluePlayer.nextCol--;
- bluePlayer.currentDirection = Direction.Left;
- }
- else if (bluePlayer.currentDirection == Direction.Right)
- {
- bluePlayer.nextRow--;
- bluePlayer.nextCol--;
- bluePlayer.currentDirection = Direction.Down;
- }
- else if (bluePlayer.currentDirection == Direction.Left)
- {
- bluePlayer.nextRow++;
- bluePlayer.nextCol++;
- bluePlayer.currentDirection = Direction.Up;
- }
- }
- else if (bluePlayer.movesCollection[i] == 'M')
- {
- bluePlayer.currentRow = bluePlayer.nextRow;
- bluePlayer.currentCol = bluePlayer.nextCol;
- if (bluePlayer.currentDirection == Direction.Up)
- {
- bluePlayer.nextRow++;
- }
- else if (bluePlayer.currentDirection == Direction.Down)
- {
- bluePlayer.nextRow--;
- }
- else if (bluePlayer.currentDirection == Direction.Right)
- {
- bluePlayer.nextCol++;
- }
- else if (bluePlayer.currentDirection == Direction.Left)
- {
- bluePlayer.nextCol--;
- }
- // if we hit M then we continue
- bluePlayerIndexStart = i + 1;
- break;
- }
- }
- #endregion
- //check if in matrix
- if (redPlayer.currentRow < 0)
- {
- redPlayer.currentRow = 0;
- redPlayer.Loose = true;
- }
- if (redPlayer.currentRow == matrix.GetLength(0))
- {
- redPlayer.currentRow = matrix.GetLength(0) - 1;
- redPlayer.Loose = true;
- }
- if (bluePlayer.currentRow < 0)
- {
- bluePlayer.currentRow =0;
- bluePlayer.Loose = true;
- }
- if (bluePlayer.currentRow == matrix.GetLength(0))
- {
- bluePlayer.currentRow = matrix.GetLength(0) - 1;
- bluePlayer.Loose = true;
- }
- //
- if (redPlayer.currentCol < 0)
- {
- redPlayer.currentCol = matrix.GetLength(1) - 1;
- }
- if (redPlayer.currentCol == matrix.GetLength(1))
- {
- redPlayer.currentCol = 0;
- }
- if (bluePlayer.currentCol < 0)
- {
- bluePlayer.currentCol = matrix.GetLength(1) - 1;
- }
- if (bluePlayer.currentCol > matrix.GetLength(1))
- {
- bluePlayer.currentCol = 0;
- }
- //check if hit same cell
- if (redPlayer.currentRow == bluePlayer.currentRow &&
- redPlayer.currentCol == bluePlayer.currentCol)
- {
- redPlayer.Loose = true;
- bluePlayer.Loose = true;
- }
- //check if cell is used
- if (matrix[redPlayer.currentRow, redPlayer.currentCol] == "used")
- {
- redPlayer.Loose = true;
- }
- if (matrix[bluePlayer.currentRow, bluePlayer.currentCol] == "used")
- {
- bluePlayer.Loose = true;
- }
- //mark cells as used
- matrix[redPlayer.currentRow, redPlayer.currentCol] = "used";
- matrix[bluePlayer.currentRow, bluePlayer.currentCol] = "used";
- //if someone is lost
- if (redPlayer.Loose || bluePlayer.Loose)
- {
- break;
- }
- }
- //print result according to who wins
- if ((redPlayer.Loose==true) && (bluePlayer.Loose==false))
- {
- Console.WriteLine("BLUE");
- }
- else if ((redPlayer.Loose==false) && (bluePlayer.Loose==true))
- {
- Console.WriteLine("RED");
- }
- else if (redPlayer.Loose == true && bluePlayer.Loose == true)
- {
- Console.WriteLine("DRAW");
- }
- else if (redPlayer.Loose ==false && bluePlayer.Loose == false)
- {
- Console.WriteLine("DRAW");
- }
- int distanceRow = Math.Abs(redPlayer.currentRow - x / 2);
- int distanceCol = Math.Abs(redPlayer.currentCol - (y/2));
- if (distanceCol > matrix.GetLength(1) / 2)
- {
- distanceCol = matrix.GetLength(1) - distanceCol;
- }
- Console.WriteLine(distanceRow + distanceCol);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement