Brainstorming

Pseudocode Maze (First Version)

void createMaze (int row, int column, int counter)
{
if (row == exitX && col == exitY)
end recursion, calling another method.
else
for (int mapRow = 0; mapRow<mazeMap.length; mapRow++)
for (int mazeCol = 0; mazeCol<mazeMap[row].length; mazeCol++)
mazeMap[row][col] = OPEN;

create random generator using math.random for 4 numbers

if (randomGenerator == 1 && row within bounds) //go north.
{
if (mazeMap[row-1][col].getWhat() == TRIED) //if it was previously on this one.
createMaze(row, col, counter++);
else
pathway[index] direction = ’N’;
mazeMap[row][col] = TRIED;
createMaze(row-1, col, counter—);
}
if (randomGenerator == 2 && within bounds) //go east
{
if (mazeMap[row][col+1].getWhat() == TRIED) //if it was previously on this one.
createMaze(row, col, counter++;
else
pathway[index] direction = ‘E’
mazeMap[row][col]= TRIED;
createMaze(row, col+1, counter--);
}
if (randomGenerator == 3 && within bounds) //go south
{
if (mazeMap[row+1][col].getWhat() == TRIED) //if it was previously on this one.
createMaze(row, col, counter++);
else
pathway[index] direction = ’S’
mazeMap[row][col] = TRIED;
createMaze(row+1, col, counter—);
}

if (randomGenerator == 4 && within bounds) //go west
{
if (mazeMap[row][col-1].getWhat() == TRIED) //if it was previously on this one.
createMaze(row, col, counter++);
else
pathway[index] direction = ‘W’
mazeMap[row][col] = TRIED;
createMaze(row, col-1, counter--);
}
}

How it was changed: Instead of checking whether it has been tried, it's checking whether the one that we're looking at has been tried, and then looking in all directions to see which it came from. In the version where I did it, I gave the computer coordinates to check (and if it hasn't been tried, making that a good path).

Pseudocode Checkers

The real pseudocode will be handed in with the program, this is just some random notes: 


If you had a 3x3 grid, the indice numbers would be as follows. So to test: 

if (pawn1Red[row-1][col+1] == emptySpace)
{
pawn1RedValue = 1;
if (userPawn[row+1][col+1] == emptySpace)
{
pawn1BlackValue = 1
}
if (emptySpaceRed == emptySpaceBlack)
{
pawn1RedValue = -1;
pawn1RedValue = -1;
}
}

In this case, both pawns would have a value of -1, and the computer would be forced to move and the user would take the opponent. At this stage, both pawns will be setDead(true). 

No comments:

Post a Comment