קוד:
using System;
using System.Collections.Generic;
using System.Text;
classProgram
{
staticvoid Apes(Paun[,] a)
{
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
a[i, j] = newPaun(i, j, true, false);
}
}
}
staticvoid SetBoard(Paun[,] a)
{
bool bla = true;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 8; j = j + 2)
{
if (bla)
{
a[i, j].Setalive(true);
}
else
{
a[i, j + 1].Setalive(true);
}
}
if (bla)
bla = false;
else
bla = true;
}
for (int i = 7; i > 4; i--)
{
for (int j = 1; j < 8; j = j + 2)
{
if (bla)
{
a[i, j - 1].Setalive(true);
a[i, j - 1].Setteam(false);
}
else
{
a[i, j].Setalive(true);
a[i, j].Setteam(false);
}
}
if (bla)
bla = false;
else
bla = true;
}
}
staticvoid Print(Paun[,] a)
{
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
if (a[i, j].Getalive() && a[i, j].Getteam())
Console.Write("b");
else
if (a[i, j].Getalive() && (!(a[i, j].Getteam())))
Console.Write("w");
else
if ((i + j) % 2 == 0)
Console.Write("*");
else
Console.Write("0");
}
Console.WriteLine("");
}
}
staticvoid Main(string[] args)
{
Paun[,] board = newPaun[8, 8];
Apes(board);
SetBoard(board);
Print(board);
int countblack = 0, countwhite=0;
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
if ((board[i, j].Getalive()) && (board[i, j].Getteam()))
countblack++;
if ((board[i, j].Getalive()) && (!(board[i, j].Getteam())))
countwhite++;
}
}
int x=0,y=0;
bool flipflop = false;
string move = "bla";
while (countblack > 0 && countwhite > 0)
{
if (!(flipflop))
{
Console.WriteLine("insert yloc of the paun you want");
y = int.Parse(Console.ReadLine());
Console.WriteLine("insert xloc of the paun you want");
x = int.Parse(Console.ReadLine());
{
if ((board[y, x].Getalive() == !flipflop) && (board[y, x].Getteam() == flipflop))
Console.WriteLine("insert move(moveleft,moveright,eatleft,eatright)");
move = Console.ReadLine();
if (move == "moveleft")
{
board[y, x].Setalive(false);
board[y--, x--].Setalive(true);
board[y--, x--].Setteam(false);
Print(board);
}
}
}
}
}
}
קוד:
using System;
using System.Collections.Generic;
using System.Text;
publicclassPaun
{
privateint yloc;
privateint xloc;
privatebool team;
privatebool alive;
public Paun()
{
}
public Paun(int xloc,int yloc,bool team,bool alive)
{
this.xloc = xloc;
this.yloc = yloc;
this.team = team;
this.alive = alive;
}
publicint Getxloc()
{
return xloc;
}
publicint Getyloc()
{
return yloc;
}
publicbool Getteam()
{
return team;
}
publicbool Getalive()
{
return alive;
}
publicvoid Setalive(bool alive)
{
this.alive = alive;
}
publicvoid Setteam(bool team)
{
this.team = team;
}
publicvoid MoveRight() /*true=black*/
{
if (team)
{
yloc++;
xloc++;
}
else
{
xloc--;
yloc++;
}
}
publicPaun[,] MoveLeft(Paun[,] a)/*true=black*/
{
if (team)
{
yloc--;
xloc++;
}
else
{
xloc--;
yloc--;
}
}
publicvoid EatRight()/*true=black*/
{
if (team)
{
yloc+=2;
xloc+=2;
}
else
{
xloc-=2;
yloc+=2;
}
}
publicvoid EatLeft()/*true=black*/
{
if (team)
{
yloc-=2;
xloc+=2;
}
else
{
xloc-=2;
yloc-=2;
}
}
}