YESSSSSSSSSSSSSSSSSSSSSSS

Home Forums General Chat YESSSSSSSSSSSSSSSSSSSSSSS

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #2807
    David
    Participant

    FINALLY, AFTER ALL THIS WHILE, FINALLY FIXED IT.

    I just wanna post this for no reason whatsoever, if you’re learning Java, you should know this. It’s the basic stuff! OMG, TOOK ME 30 MINUTES TO SCRIPT THIS. T___T I SUCK.

    Script said:
    /*
    * File: StoneMasonKarel.java
    * ————————–
    * Cleans any world with rows that has spaces of 4.
    * Repairs the stones where needed.
    * Written by David G.
    */
    import stanford.karel.*;

    public class StoneMasonKarel extends SuperKarel {

    /*
    * Start code, run defines the entire process. Repeats 5 times
    */
    public void run() {
    while (frontIsClear()) {
    cleanWorld();
    }
    }

    private void cleanWorld() {
    if (facingEast()) {
    cleanWestRow();
    }
    if (facingWest()) {
    cleanEastRow();
    }
    }
    /*
    * Cleans the entire row.
    */
    private void cleanWestRow() {
    while (frontIsClear()) {
    placeBeeper();
    }
    if (frontIsBlocked()) {
    turnLeft();
    checkWall();
    move();
    goLeft();
    }
    }
    /*
    * Puts a beeper if no beeper is present
    */
    private void placeBeeper() {
    if (noBeepersPresent()) {
    putBeeper();
    } else {
    moveFour();
    doubleBeeper();
    }
    }

    private void doubleBeeper() {
    if (noBeepersPresent()) {
    putBeeper();
    }
    }
    /*
    * Moves four spaces to avoid long code
    */
    private void moveFour() {
    move();
    move();
    move();
    move();
    }

    private void cleanEastRow() {
    while (frontIsClear()) {
    placeBeeper();
    }
    if (frontIsBlocked()) {
    turnRight();
    checkWall();
    move();
    goRight();
    }
    }

    private void goRight() {
    if (noBeepersPresent()) {
    putBeeper();
    turnRight();
    } else {
    turnRight();
    }
    }

    private void goLeft() {
    if (noBeepersPresent()) {
    putBeeper();
    turnLeft();
    } else {
    turnLeft();
    }
    }

    private void checkWall() {
    if (frontIsBlocked()) {
    turnAround();
    }
    }
    }

    Ew. It looks messy because tabs don’t work. :3

    Video of what it does coming soon. :3

    EDIT: Uploaded, might be processing.

    Problem definition:
    Karel has been hired to repair the damage done to the Quad in the 1989 earthquake. In
    particular, Karel is to repair a set of arches where some of the stones (represented by
    beepers, of course) are missing from the columns supporting the arches.
    Your program should work on the world shown above, but it should be general enough to
    handle any world that meets certain basic conditions as outlined at the end of this
    problem. There are several example worlds in the starter folder, and your program should
    work correctly with all of them.
    When Karel is done, the missing stones in the columns should be replaced by beepers, so
    that the final picture resulting from the world shown above would look like complete arches.

    Karel may count on the following facts about the world:
    • Karel starts at 1st Avenue and 1st Street, facing east, with an infinite number of
    beepers.
    • The columns are exactly four units apart, on 1st, 5th, 9th Avenue, and so forth.
    • The end of the columns is marked by a wall immediately after the final column. This
    wall section appears after 13th Avenue in the example, but your program should work
    for any number of columns.
    • The top of the column is marked by a wall, but Karel cannot assume that columns are
    always five units high, or even that all columns are the same height.
    • Some of the corners in the column may already contain beepers representing stones

    #6821
    Nass
    Participant

    *victory music*

    Level Up!

    #6822
    David
    Participant

    Uploaded video. 😀 Might be processing.

    Moving on to Java.

    #6823
    SilverFx
    Participant

    *blink* That’s cool. If I knew what it meant. XD

    #6825
    David
    Participant

    Just look at the video. =) It matches up evenly I think… ;-;

    #6826
    SilverFx
    Participant

    I know, I’ve watched the video. So it.. goes around placing.. diamonds on .. empty spaces..? *Squints*

    #6829
    David
    Participant

    Rawr. Yeah. It checks if there’s a Beeper present, if there is, it places a beeper, then moves 4 spaces.

    It also checks if the walls are blocking it, if it they are, he either turns around and goes for the next row, or just stop entirely because both his top and bottom are blocked.

    o.O Hope that made sense.

    #6831
    SilverFx
    Participant

    Oh. ^_^; Yeah, that made sense. It’s just a coding exercise, I gather?

    #6832
    David
    Participant

    Yep. There was also a contest to see if you can do mundane stuff, but in an extraordinary way, sort of like a Rube Goldberg Machine. 😉

    So for example, the task would be to carry a stone from Point A to Point C, but instead, you make the robot jump over invisible hurdles before doing so, and not just in a set world, but in any general world.

    So math gets in the way sometimes. XD

    #6833
    SilverFx
    Participant

    I see. I love Rube Goldberg Machines 😀

    ^_^

    #6834
    Aaron
    Participant

    @Silver: THAT WUZ AWSUM!

    Wish I knew how to Java….

    #6846
    FunnyFroggy
    Participant

    lul your Karel looks like some old version or something. o_O

    #6853
    MasterCheeze
    Participant

    I don’t see a whale anywhere. What gives?

    #6868
    Ezyan
    Participant

    …lol I remember now why I can’t code.

    ^__________^

    #6888
    Blackboy0
    Participant

    Congrats David. That’s more than I can do in Java 😛 Just learning it though…

    I’m more into C++ and Python, since WoW servers need ’em to run 🙂

Viewing 15 posts - 1 through 15 (of 23 total)
  • You must be logged in to reply to this topic.