What algorithm best describe this?
The role of arbiter is to check which rank is higher and then remove the lower rank pieces..
I use a lot if IF CONDITIONS to make it work..
Do you know any algorithm that can i put on my papers?
Thanks!
If you need help sorting arrays, tell us more about the kind of data that's in them.
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play
"Reducing the world to mathematical equations!"
Can you describe the game, in English, and what the referee or arbiter does?
Do you know any algorithm that can i put on my papers?
[/quote]
Is this for school?
No, not for school, I just want to make a documentation on instruction how I created the game and algorithm how it works.
The arbiter of the game is the referee..
Both players cannot see others pieces.. And if they collide on the same cell the arbiter will look what piece wins..
The arbiter will be the one who will remove, retain or advance the pieces.
I would probably not use any conditionals to determine who wins, but a lookup table instead:
enum Piece {FiveStarGeneral, FourStarGeneral, ThreeStarGeneral, /*...*/, Flag, NPieces};
enum BattleResult {AttackerWins, NobodyWins, DefenderWins};
BattleResult compute_battle(Piece attacker, Piece deffender) {
static BattleResult const result_table[NPieces][NPieces] = {
{NobodyWins, AttackerWins, AttackerWins, /*...*/},
{DefenderWins, NobodyWins, AttackerWins, /*...*/},
/*...*/
};
return table[attacker][defender];
}
Not all algorithms have a fancy name. You simply implemented the rules of the game. So just state the rules of the game as they appear on the Wikipedia page.
-me
He's already written the logic, he just wants a name.
If you are responding to my code, I should have made it clear that the real answer to the question was the first paragraph of my post. The code is just an idea I threw in for free.
{
ARank = Integer.parseInt(Board[intBoardTempOne][intBoardTempTwo].getText());
System.out.println(ARank);
Sender.GrabInfo(intCurrentX, intCurrentY);
try
{
Thread.sleep(50L);//Pause the Program
}
catch(InterruptedException interruptedexception1) { }
YourTurn = false;
Sender.setTurn("true");
//When Pieces are the same on rank
if(ARank == BRank)
{
txtArea.append("\n<System> Both Pieces have died coming out of this battle");
ChatSocket.sendText("z<System> Both Pieces have died coming out of this battle");
Board[intBoardTempOne][intBoardTempTwo].setText("");
Board[intCurrentY][intCurrentX].setText("");
removePic(intCurrentY, intCurrentX);
removePic(intBoardTempOne, intBoardTempTwo);
Sender.EraseEnemy(intCurrentX, intCurrentY);
Sender.EraseEnemy(intBoardTempTwo, intBoardTempOne);
} else
// When Host Private and Client's Spy
if(ARank == 1 && BRank == 14)
{
txtArea.append("\n<System> You have come out victorious, from your battle.");
ChatSocket.sendText("z<System> You have been defeated through a horrendous battle.");
Board[intCurrentY][intCurrentX].setText(Board[intBoardTempOne][intBoardTempTwo].getText());
setPic(intCurrentY, intCurrentX, Board[intBoardTempOne][intBoardTempTwo].getText());
Board[intBoardTempOne][intBoardTempTwo].setText("");
removePic(intBoardTempOne, intBoardTempTwo);
Sender.EraseEnemy(intBoardTempTwo, intBoardTempOne);
Sender.sendPos(intCurrentX, intCurrentY);
} else
// When Host Spy and Client's Private
if(ARank == 14 && BRank == 1)
{
txtArea.append("\n<System> You have been defeated through a horrendous battle");
ChatSocket.sendText("z<System> You have come out victorious, from your battle.");
Board[intBoardTempOne][intBoardTempTwo].setText("");
removePic(intBoardTempOne, intBoardTempTwo);
Board[intCurrentY][intCurrentX].setText("enemy");
setPic(intCurrentY, intCurrentX, "enemy");
Sender.EraseEnemy(intBoardTempTwo, intBoardTempOne);
Sender.EraseEnemy(intCurrentX, intCurrentY);
Sender.SendLabel(BRank, intCurrentX, intCurrentY);
} else
// When Host have higher rank of piece than the Client
if(ARank > BRank)
{
txtArea.append("\n<System> You have come out victorious from your battle.");
ChatSocket.sendText("z<System> You have been defeated through a horrendous battle.");
Board[intCurrentY][intCurrentX].setText(Board[intBoardTempOne][intBoardTempTwo].getText());
setPic(intCurrentY, intCurrentX, Board[intBoardTempOne][intBoardTempTwo].getText());
Board[intBoardTempOne][intBoardTempTwo].setText("");
removePic(intBoardTempOne, intBoardTempTwo);
Sender.EraseEnemy(intBoardTempTwo, intBoardTempOne);
Sender.sendPos(intCurrentX, intCurrentY);
} else
// When Host have lower rank of piece than the Client
if(ARank < BRank)
{
txtArea.append("\n<System> You have been defeated through a horrendous battle");
ChatSocket.sendText("z<System> You have come out victorious, from your battle.");
Board[intBoardTempOne][intBoardTempTwo].setText("");
removePic(intBoardTempOne, intBoardTempTwo);
Board[intCurrentY][intCurrentX].setText("enemy");
setPic(intCurrentY, intCurrentX, "enemy");
Sender.EraseEnemy(intBoardTempTwo, intBoardTempOne);
Sender.EraseEnemy(intCurrentX, intCurrentY);
Sender.SendLabel(BRank, intCurrentX, intCurrentY);
}
// When two flag meets
if(ARank == 0 && BRank == 0)
{
setPic(intCurrentY, intCurrentX, "" + BRank);
setPic(intBoardTempTwo, intBoardTempTwo, "" + ARank);
Sender.SendLabel(ARank, intBoardTempTwo, intBoardTempOne);
Sender.SendLabel(BRank, intCurrentX, intCurrentY);
Sender.sendYouWin();
txtArea.append("\n<System> Tie game!!");
DisableBoard();
Sender.sendTie();
} else
if(ARank == 0)
{
setPic(intCurrentY, intCurrentX, "" + BRank);
setPic(intBoardTempTwo, intBoardTempTwo, "" + ARank);
Sender.SendLabel(ARank, intBoardTempTwo, intBoardTempTwo);
Sender.sendYouWin();
txtArea.append("\n<System> Good game, try again next time.");
txtArea.append("\n<System> Winner will choose to start next game or not.");
DisableBoard();
} else
if(BRank == 0)
{
setPic(intCurrentY, intCurrentX, "" + BRank);
setPic(intBoardTempTwo, intBoardTempTwo, "" + ARank);
Sender.SendLabel(ARank, intBoardTempTwo, intBoardTempTwo);
Sender.SendLabel(BRank, intCurrentX, intCurrentY);
txtArea.append("\n<System> Congratulations, you WIN!");
DisableBoard();
Sender.sendYouLose();
ConfirmNewG.setVisible(true);
}
ConfirmMove.setVisible(false);
Moving = false;
ReturnBoard();
Write a single function that checks two pieces and returns a result of who won (or a tie). Then based on that result, you only have a couple of branches to tell the player and the game what happened.
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play
"Reducing the world to mathematical equations!"