Az alábbi letöltési lehetőségek közül választhatsz: (
segítség)
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: us-ascii
Méret: 2 KB
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace sakk
{
class Coords
{
public int x, y;
public Coords(int _x, int _y)
{
x = _x;
y = _y;
}
}
class sakk
{
private int x, y;
private int[,] table = new int[8, 8];
private Queue<Coords> q = new Queue<Coords>();
public sakk()
{
StreamReader ins = new StreamReader("sakk.be");
string[] line = ins.ReadLine().Split(' ');
x = int.Parse(line[1]) - 1;
y = int.Parse(line[0]) - 1;
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
table[i, j] = -1;
}
}
table[x, y] = 0;
q.Enqueue( new Coords( x, y ) );
jump();
printOut();
}
private void printOut()
{
StreamWriter outs = new StreamWriter("sakk.ki");
for (int j = 0; j < 8; j++)
{
for (int i = 0; i < 8; i++)
{
if (i != 0) outs.Write(" ");
outs.Write( table[i, j] );
}
outs.WriteLine();
}
outs.Close();
}
private void jump()
{
Coords c;
while (q.Count != 0)
{
c = q.Dequeue();
checkPos(c, +2, +1);
checkPos(c, +2, -1);
checkPos(c, -2, +1);
checkPos(c, -2, -1);
checkPos(c, +1, +2);
checkPos(c, +1, -2);
checkPos(c, -1, +2);
checkPos(c, -1, -2);
}
}
private void checkPos(Coords c, int dx, int dy)
{
if (c.x + dx >= 0 && c.x + dx < 8 && c.y + dy >= 0 && c.y + dy < 8)
{
if (table[c.x + dx, c.y + dy] == -1)
{
table[c.x + dx, c.y + dy] = table[c.x, c.y] + 1;
q.Enqueue( new Coords( c.x + dx, c.y + dy ) );
}
}
}
static void Main(string[] args)
{
new sakk();
}
}
}