Advertisement
Guest User

bit chess

a guest
Mar 29th, 2015
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CurrencyCheck
  8. {
  9.     class Bits
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             long[] board = new long[8];
  14.             string input = Console.ReadLine();
  15.             int line = 0;
  16.             int pos = 0;
  17.             board[line] ^= (1 << pos);
  18.             while (input != "stop")
  19.             {
  20.                 bool toContinue = false;
  21.                 int previousLine = line;
  22.                 int previousPos = pos;
  23.                 switch (input)
  24.                 {
  25.                     case "left down":
  26.                         line++;
  27.                         pos += 2;
  28.                         break;
  29.                     case "down right":
  30.                         line += 2;
  31.                         pos--;
  32.                         break;
  33.                     case "right up":
  34.                         pos -= 2;
  35.                         line--;
  36.                         break;
  37.                     case "down left":
  38.                         line += 2;
  39.                         pos++;
  40.                         break;
  41.                     case "left up":
  42.                         line--;
  43.                         pos += 2;
  44.                         break;
  45.                     case "up left":
  46.                         line -= 2;
  47.                         pos++;
  48.                         break;
  49.                     case "up right":
  50.                         line -= 2;
  51.                         pos--;
  52.                         break;
  53.                     default:
  54.                         toContinue = true;
  55.                         break;
  56.                 }
  57.                 if (toContinue)
  58.                 {
  59.                     input = Console.ReadLine();
  60.                     continue;
  61.                 }
  62.                 if (line >= 8 || pos >= 8 || line < 0 || pos < 0)
  63.                 {
  64.                     line = previousLine;
  65.                     pos = previousPos;
  66.                 }
  67.                 else
  68.                 {
  69.                     board[line] ^= (1 << pos);
  70.                 }
  71.                 input = Console.ReadLine();
  72.             }
  73.  
  74.             StringBuilder sb = new StringBuilder();
  75.             for (var i = 0; i < board.Length; i++)
  76.             {
  77.                 if (board[i] != 0)
  78.                 {
  79.                     sb.AppendLine(board[i].ToString());
  80.                 }
  81.             }
  82.  
  83.             if (string.IsNullOrEmpty(sb.ToString()))
  84.             {
  85.                 Console.WriteLine("[Board is empty]");
  86.             }
  87.             else
  88.             {
  89.                 Console.WriteLine(sb.ToString());
  90.             }
  91.         }
  92.  
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement