Skip to content

Building Tower Problem #10

@harunhary123-rgb

Description

@harunhary123-rgb

Problem: The stones aren't being placed. What could I change? (The tower building is within an other game which was coded by professionals, as well as the map).

This is the task: Your task is to build a tower on an empty map using the robot and by placing stones.

To do this, add the following function:

[game, player] = buildTower(towerWidth, towerLength, towerHeight).

The result should be: The tower should be built in the upper right corner. The base of the tower should be rectangular with

a width of towerWidth in the x-direction and a length of towerLength in the y-direction. You can assume that towerWidth

and towerLength are each at least 2. The height should be achieved by placing stones on top of each other

and should ultimately equal towerHeight. The area inside the tower must be filled. No other constructions are allowed outside
the tower. The map must be at least the size of the tower.

Important: In your template, the robot's starting position is in the upper left corner, facing east. Your solution should

however, work regardless of the starting position and orientation. This independence will be verified!

This is my code:
[game, player]=initializeGame('empty');
[game, player] = buildTower(towerWidth, towerLength, towerHeight);
function [game, player]=buildTower(towerWidth, towerLength, towerHeight)
[game, player]=createGame();
[mapHeight, mapWidth]=size(game.Map);
targetX=mapWidth-towerWidth+1;
targetY=1;
moveTo(player, targetX, targetY);
faceDirection(player, "east");

for row=1:towerLength
    for col=1:towerWidth
        for h=1:towerHeight
            putStone(player);
        end
        if col<towerWidth
            moveForward(player);
        end
    end
    if row<towerLength
        if mod(row,2)==1
            turnRight(player);
            moveForward(player);
            turnRight(player);
        else
            turnLeft(player);
            moveForward(player);
            turnLeft(player);
        end
    end
end

end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions