Ich bin zwar schon den ganzen Tag müde, aber versuche es trotzdem. Ist aber rein VHIDT und basiert nicht auf deinen bisherigen Sources.
Java:
public class ComputerStep
{
private static final byte DIRECTORY_EAST = 0;
private static final byte DIRECTORY_SOUTH = 1;
private static final byte DIRECTORY_DIA_SOUTH_EAST = 2;
private static final byte DIRECTORY_DIA_SOUTH_WEST = 3;
private static final Dimension[] DIRECTORY_STEPS = {
new Dimension(1, 0),
new Dimension(0, 1),
new Dimension(1, 1),
new Dimension(-1, 1);
};
private static final Step[] STEPS = {
new Step(new Point(0, 0), DIRECTORY_EAST),
new Step(new Point(0, 0), DIRECTORY_SOUTH),
new Step(new Point(0, 0), DIRECTORY_DIE_SOUTH_EAST),
new Step(new Point(1, 0), DIRECTORY_SOUTH),
new Step(new Point(2, 0), DIRECTORY_SOUTH),
new Step(new Point(0, 1), DIRECTORY_EAST),
new Step(new Point(0, 2), DIRECTORY_EAST),
};
private GameButton[][] buttons;
private Point foundetFreeField;
public static void start()
{
boolean bool = false;
for(byte b = 0; b < STEPS.lenght && !bool; b++)
{
foundetFreeField = null;
Step step = STEPS[b];
bool = computing(step.getPoint(), step.getDirectory(), 1, 0, 0);
}
}
private static boolean computing(Point point, byte dir, byte stepCount, byte foundetFree, byte foundetEnemy)
{
boolean b = false;
if(stepCount != 3)
{
GameButton gameButton = buttons[point.x][point.y];
if(gameButton.getPlayerStone() == null)
{
foundetFree++;
foundetFreeField = point;
}
else if(gameButton.getPlayerStone().getPlayer == Stone.HUMAN)
foundetEnemy++;
Dimension dirSteps = DIRECTORY_STEPS[dir];
b = computing(new Point(point.x + dirSteps.width, point.y + dirSteps.height), dir, stepCounter + 1, foundetFree, foundetEnemy);
}
else
{
if(foundetFree == 1 && foundetEnemy == 2)
b = true;
}
return(b);
}
private static class Step
{
private Point p;
private byte dir;
private Step(Point p, byte dir)
{
this.p = p;
this.dir = dir;
}
private Point getPoint()
{
return(p);
}
private Point getDirectory()
{
return(dir);
}
}
Zuletzt bearbeitet: