2007'den beri7 mesaj
beyler programı c# da çalıstırdım ama java ya çeviremiyorum. tam olarak kodların karşılığını bulamadım. Int32.TryParse(matrix[i, y], out koordinat nasıl çeviricem acaba..
yardımcı olursanız sevinirim teşekkürler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
public static String[,] matrix;
public static int denemeSayisi;
public static int tekrarDenemeSayisi;
static void Main(string[] args)
{
matrix = new String[8, 8];
denemeSayisi = 0;
tekrarDenemeSayisi = 0;
matrix = new String[8, 8];
denemeSayisi = 0;
tekrarDenemeSayisi = 0;
Boolean matrixKontrol = true;
int count = 0;
int koordinat=0;
while (matrixKontrol)
{
degerAta();
count = 0;
for (int i = 0; i < 8; i++)
{
for (int y = 0; y < 8; y++)
{
if (matrix[i, y] == "*" || Int32.TryParse(matrix[i, y], out koordinat))
{
count++;
}
if (count >= 64)
{
matrixKontrol = false;
}
}
}
}
ekranaYazdır();
}
public static void ekranaYazdır()
{
String str = "";
for (int i = 0; i < 8; i++)
{
str += "\n";
for (int y = 0; y < 8; y++)
{
str += matrix[i, y] + "\t";
}
}
Console.WriteLine(str);
Console.WriteLine("Deneme sayısı : " + denemeSayisi);
Console.WriteLine("Tekrar atanan sayı : " + tekrarDenemeSayisi);
}
public static void degerAta()
{
denemeSayisi++;
Random rd = new Random();
int x = rd.Next(8);
int y = rd.Next(8);
int d5 = 0;
if ((x == 0 || y == 7 || y == 0 || x == 7) && matrix[x, y] == null)
{
matrix[x, y] = rd.Next(5) + 1 + "";
return;
}
if (x > 0 && y < 7 && x < 7 && y > 0)
{
Boolean result = Int32.TryParse(matrix[x, y], out d5);
if (result)
{
return;
}
else if ((matrix[x, y] == "" || matrix[x, y] == null) && matrix[x, y] != "*")
{
int d1 = 0;
int d2 = 0;
int d3 = 0;
int d4 = 0;
result = Int32.TryParse(matrix[x + 1, y + 1], out d1);
if (result)
{
result = Int32.TryParse(matrix[x - 1, y - 1], out d2);
if (result)
{
d1 += d2;
result = Int32.TryParse(matrix[x - 1, y + 1], out d3);
if (result)
{
d1 += d3;
result = Int32.TryParse(matrix[x + 1, y - 1], out d4);
if (result)
{
d1 += d4;
for (int i = 1; i < 6; i++)
{
d1 += i;
tekrarDenemeSayisi++;
if (d1 == 12 || d1 == 13 || d1 == 14 || d1 == 15 || d1 == 16)
{
matrix[x, y] = "*";
return;
}
d1 -= i;
if (i == 5)
{
matrix[x, y] = "*";
}
}
}
}
}
}
}
if (!result)
{
matrix[x, y] = (rd.Next(5) + 1) + "";
}
}
}
}
}
yardımcı olursanız sevinirim teşekkürler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
public static String[,] matrix;
public static int denemeSayisi;
public static int tekrarDenemeSayisi;
static void Main(string[] args)
{
matrix = new String[8, 8];
denemeSayisi = 0;
tekrarDenemeSayisi = 0;
matrix = new String[8, 8];
denemeSayisi = 0;
tekrarDenemeSayisi = 0;
Boolean matrixKontrol = true;
int count = 0;
int koordinat=0;
while (matrixKontrol)
{
degerAta();
count = 0;
for (int i = 0; i < 8; i++)
{
for (int y = 0; y < 8; y++)
{
if (matrix[i, y] == "*" || Int32.TryParse(matrix[i, y], out koordinat))
{
count++;
}
if (count >= 64)
{
matrixKontrol = false;
}
}
}
}
ekranaYazdır();
}
public static void ekranaYazdır()
{
String str = "";
for (int i = 0; i < 8; i++)
{
str += "\n";
for (int y = 0; y < 8; y++)
{
str += matrix[i, y] + "\t";
}
}
Console.WriteLine(str);
Console.WriteLine("Deneme sayısı : " + denemeSayisi);
Console.WriteLine("Tekrar atanan sayı : " + tekrarDenemeSayisi);
}
public static void degerAta()
{
denemeSayisi++;
Random rd = new Random();
int x = rd.Next(8);
int y = rd.Next(8);
int d5 = 0;
if ((x == 0 || y == 7 || y == 0 || x == 7) && matrix[x, y] == null)
{
matrix[x, y] = rd.Next(5) + 1 + "";
return;
}
if (x > 0 && y < 7 && x < 7 && y > 0)
{
Boolean result = Int32.TryParse(matrix[x, y], out d5);
if (result)
{
return;
}
else if ((matrix[x, y] == "" || matrix[x, y] == null) && matrix[x, y] != "*")
{
int d1 = 0;
int d2 = 0;
int d3 = 0;
int d4 = 0;
result = Int32.TryParse(matrix[x + 1, y + 1], out d1);
if (result)
{
result = Int32.TryParse(matrix[x - 1, y - 1], out d2);
if (result)
{
d1 += d2;
result = Int32.TryParse(matrix[x - 1, y + 1], out d3);
if (result)
{
d1 += d3;
result = Int32.TryParse(matrix[x + 1, y - 1], out d4);
if (result)
{
d1 += d4;
for (int i = 1; i < 6; i++)
{
d1 += i;
tekrarDenemeSayisi++;
if (d1 == 12 || d1 == 13 || d1 == 14 || d1 == 15 || d1 == 16)
{
matrix[x, y] = "*";
return;
}
d1 -= i;
if (i == 5)
{
matrix[x, y] = "*";
}
}
}
}
}
}
}
if (!result)
{
matrix[x, y] = (rd.Next(5) + 1) + "";
}
}
}
}
}