1. If you're looking for help-related things (for example, the key rebinding tutorial), please check the FAQ and Q&A forum! A lot of the stickies from this forum have been moved there to clean up space.
    Dismiss Notice

So... I've made Snake Game

Discussion in 'Starbound Discussion' started by Proydoha, Nov 29, 2015.

  1. Proydoha

    Proydoha Phantasmal Quasar

    Title. Also bad English.

    So... I've made it in vanilla starbound in current stable (Pleased Giraffe Update 5). Decided to finish it now, because new patch may (or may not) mess up my wiring and it took too much time to abandon it halfway. Got all the materials to build it in admin mode. Noone sane should ever attempt collecting this much copper.

    Video demonstration:
    (Actually I've made gif but Steam refused to upload it... And I'm kinda fishing for likes here so... Whatever)



    Behind the scenes (/fullbright):

    3rd floor:
    [​IMG]

    2nd floor:
    [​IMG]

    1st floor:
    [​IMG]
    (Should it be called "ground floor" and the second one - "first floor" and so on? As non English speaker I never understood logic behind this.)


    Now let's turn wires on:

    3rd floor:
    [​IMG]

    2nd floor:
    [​IMG]

    1st floor:
    [​IMG]

    My snake can't be longer then 10 segments because to make it longer I had to build that top-left section of the 3-rd floor over and over again. There is 9x9 game screen (81 lamps). My memory section can memorize only 10. To cover entire screen I need 7 more sections. And one row to say "you won". I'm too lazy for this.

    Also it's not intended that it starts off with head and one additional segment. Probably I've miscalculated something when I was building my game loop.

    I can explain it how everything works. Probably I'll do it later.

    Truth to be told... It's not working properly every single time. Sometimes you have to flip a few debugging switches here and there to make it work again. Sometimes entire snake body messes up because I didn't take wire timeings seriusly and moon that rotates this ocean planet is causing tides that affect my wires. Or something like that.

    I've recorded it on first try but when I decided to make another video it failed me two times in the row. Fourth one was once again lucky. So it's safe to say that it's 50/50.

    Also attaching planet here: http://s000.tinyupload.com/index.php?file_id=53245931643995361807
    I'm using this file hosting for the first time in my life. If you don't trust it, don't use it. And if I were you I wouldn't trust anyone. Apparently .world is not on the list of allowed filetypes.
    Coordinates:
    596374662
    -449207693
    It's Alpha Gaia Minoris VII a
    Radioactive Star, top left ocean planet
     
    Jellybean168, Wolf1e, LilyV3 and 28 others like this.
  2. Garatgh Deloi

    Garatgh Deloi Master Astronaut

    Awesome. I have no other words to describe it.
     
  3. I'm... I'm not sure if I'm impressed or worried. I wouldn't even know how to begin to do this. Kudos to you.
     
  4. The | Suit

    The | Suit Agent S. Forum Moderator

    The fact you were able to figure this out - is just mind blowing. Just wow.
     
  5. Proydoha

    Proydoha Phantasmal Quasar

    Explanation time! I'm not the best teacher in the world and language barrier will probably make this hard to understand but I've made lots of gifs to illustrate my thoughts.

    First things first. I'm using switches everywhere instead of buttons because I can get one tick long signal whenever I flip my switch up or down. It has a price of few ticks of delay but at least I don't have to wait until button "unpress" itself.
    Other non-obvious thing is that you can't connect multiple switches to this one tick generator. Well... You can but you have to make sure that every other switch that is connected to it is switched off or the one you're using now will refuse to work.

    Here's how my switch-button thing looks like:

    SB_Switch_Button.gif
    Wires:
    SB_Switch_Button_Wires.png
    That last one XOR is unnececery.
    First: it can be OR. I've used it accidently and rolled with it.
    Second: you can connect outputs of both END's to the thing that you want to activate. But if you have to connect it to dozens of inputs it's better for your own sanity to have those.

    Okay. Moving on.
    First thing that I've made was snake's head and tail.
    Main idea here is that snake's head moves across the "board" and "draws" it's body. And tail is moving using the same trajectory as head "erasing" it's body from the "board".
    "Board" that keeps track of the snake's body is 9x9 cluster of persistent switches on the bottom of the 2nd floor in my first post.

    Here's how head and tail was made.
    Everybody knows about this beautiful way of using latches:
    SB_Loop_1.gif
    Wires:
    SB_Loop_1_Wires.png

    I've figured out that you can upgrade it with AND switches:
    SB_Loop_2.gif
    Wires:
    SB_Loop_2_Wires.png
    The signal moves upwards here.
    RED switch sets bottom latch into activated state.
    BLUE switch moves signal upwards if Small Wall Switch is ON. If it's OFF it resets whole line of latches into non active state.
    I use this to reset snake's head and tail position into the center of the board at the beginning of each game.

    Another upgrade to this design is that you, with a little change, can use this to move signal in both directions. You just need another row of AND-switches:
    SB_Loop_3.gif
    Wires:
    SB_Loop_3_Wires.png

    And another super simple concept:
    SB_Board_1.gif
    Wires:
    SB_Board_1_Wires.png

    Looks self-explanetory. Bottom row of switches attached to columns of the 3x3 AND-switch cluster. Left column of switches attached to rows of the 3x3 AND-switch cluster.
    Works like Cartesian coordinate system. Bottom row is X-axis. Left column is Y-axis.

    If you mix this with rows and columns of latches you'll get snake's head and tail that can navigate thrugh 2D space.
    You can see it's implementation in the middle of the second and first floors.
    The one that's on the first floor is the tail.
    The one that's on the second floor is the head.

    To the right of the both of them there are 9x9 clusters of AND-switches. Those clusters send signal to "draw" or "erase" snake's body.
    I send my signal to do so to the OR-switches that labeled "PLACE" and "REMOVE".



    Then I made input to control it's movement. Basic idea is this:
    Whenever I push button (flip switch) I want to know should snake's head move horisontally or not and direction of movement (left or right). Also I want to know should it move vertically or not and direction of movement (up or down).
    This resolves on 3rd floor. There are set of four latches near colorful switches. If you look at the wires it looks like a mess but actually it's something similiar to this:
    SB_Input_1.png
    SB_Input_2.png
    SB_Input_3.png
    SB_Input_4.png
    SB_Input_5.png


    Connected simultaneously:
    SB_Input_6.png

    SB_Input.gif

    Each input activates it's own predefined set of latches.

    Those four parameters also used for tail movement. And if snake's body is longer then one piece then you have to memorize it in a tricky way.
    Here's what I've came up with:

    SB_Memory_Cell_Wires.png

    Looks complicated. It's not.
    Top, left and right little pieces are there just for switch-buttons. Don't pay too much attention to them.

    So, left part is basically the same column of latches that transfers some signal upwards. This signal is snake's body length. If signal is on the bottom - body is short. If it's at the top - body is long.
    Here it is in action. When I flip BLUE switch I'm increasing snake's body length. This happens every time snake eats apple. RED switch and ORANGE small wall switch is there just for manual reset:

    SB_Memory_Cell_1.gif


    Second section of this memory cell is memory itself:
    SB_Memory_Cell_2.gif SB_Memory_Cell_3.gif

    When I flip GREEN switch I save signal from YELLOW small wall switch into my memory cell to the slot that is defined by snake's length.
    Snake's head saves it's movement variables to the top of this memory cell. It's tail reads them from the bottom of this memory cell.

    Whenever snake moves and not eats any apples whole memory cell should be shifted downwards witch is basically same signal transfering latches as before:
    SB_Memory_Cell_4.gif

    I flip purple switch - everything shifts downwards.

    And that's it. Only thing that I'm not explained is RNG that generates apples. It's really not RNG. It's same thing that moves head/tail only it's moving constantly and "drawing" apples on the apple memory cluster when head collides with one of them.

    Game loop (little ugly OR-switch underwater appendix) looks like this:
    MOVE HEAD
    Check if there is collision with body. If not then
    DRAW HEAD ONTO BODY CLUSTER
    SAVE HEAD MOVEMENT PARAMETERS
    Check if there is collision with apple. If not then
    ERASE TAIL FROM BODY CLUSTER
    MOVE TAIL ACCORDING TO SAVED MOVEMENT PARAMETERS
    SHIFT MEMORY CELL
    START AGAIN

    And if there were collision with apple then
    INCREASE BODY LENGTH AND START AGAIN
    And if there were collision with body then
    GAME OVER



    So it's not that complicated but it takes too long to connect all the 9x9 AND clusters.
     
    Last edited: Nov 29, 2015
  6. This is incredible! Those wire set-up images hurt my brain.
     
  7. bartwe

    bartwe Code Cowboy

    This makes me very happy :)
     
  8. Kawa

    Kawa Tiy's Beard

    You monster.
     
  9. Apex-prey

    Apex-prey Astral Cartographer

    Holy shit snacks thats amazing it hurts my brain
     
  10. Campaigner

    Campaigner Giant Laser Beams

    This guy deserves to be immortalized in the game. This is incredible. A bit concerning, but still incredible nonetheless.
     
  11. Hel

    Hel ✨ Johto's Finest ✨ Forum Moderator

    I think after seeing this you deserve a rest :O

    This is really incredable. Although all the red lines wasn't good for my eyesight. :/ But still this is really amazing. How long did it take you to do this?
     
  12. Proydoha

    Proydoha Phantasmal Quasar

    I've felt that it needs better explanation, so I've made super long sequence of images that explains how it works step by step showing few game cycles as an example.


    SB_Explanation_01.png SB_Explanation_02.png SB_Explanation_03.png SB_Explanation_04.png SB_Explanation_05.png SB_Explanation_06.png SB_Explanation_07.png SB_Explanation_08.png SB_Explanation_09.png SB_Explanation_10.png SB_Explanation_11.png SB_Explanation_12.png SB_Explanation_13.png SB_Explanation_14.png SB_Explanation_15.png SB_Explanation_16.png SB_Explanation_17.png SB_Explanation_18.png SB_Explanation_19.png SB_Explanation_19_1.png SB_Explanation_20.png SB_Explanation_21.png SB_Explanation_22.png SB_Explanation_23.png SB_Explanation_24.png SB_Explanation_25.png SB_Explanation_26.png SB_Explanation_27.png


    I think it took three evenings. And one morning. About two hours each. Steam says that I have 14.8 hrs last two weeks in Starbound, so I might be worng here : )

    It's second attempt. First one were uglier and failed. I've managed to figure out how to move head across the game screen and how to generate new apple when head eats the one that already existed. But when I've got to the increasing length when it eats apples I've hit brick wall and couldn't think of any solution that might work. So I've abandoned this idea until I saw this Google Doodle: http://www.google.com/doodles/george-booles-200th-birthday

    Somehow it inspired me and I flew to the new planet and started from scratch. And it worked.

    Also. Yay! I'm famous now!

    SB_Famous.png
     

    Attached Files:

  13. Hel

    Hel ✨ Johto's Finest ✨ Forum Moderator

    If I gotta be honest I thought you would have been doing this for nearly a month. Maybe longer.

    And I am really not surprised @mollygos did that. It really is amazing
     
  14. Kilowolf

    Kilowolf Big Damn Hero

    my god, this is amazing. Great job
     
  15. Proydoha

    Proydoha Phantasmal Quasar

    Well... I had it in my head longer then I've build it, that's for sure.
     
  16. Lemony Shtickit

    Lemony Shtickit Big Damn Hero

    And with all these explanations, and how long I'm guessing it took to build that thing, you said you were lazy.
     
  17. MysticMalevolence

    MysticMalevolence Oxygen Tank

    *Raises hand*

    Why?
     
  18. newtonsolo313

    newtonsolo313 Void-Bound Voyager

    wait does it run really slow because its using code inside a game
     
  19. Proydoha

    Proydoha Phantasmal Quasar

    For the most of the time when you create something and you're not compleatly clueless you know how terribly flawed your creation. Sometimes you can fix it. Sometimes you can't for a lot of reasons. And sometimes you can but you're just lazy. That's my case here. I know what exactly is wrong there. Just got lazy and capped maximum length of a snake at 10 instead of 80. There is this saying that apparently (I googled it) originates from the movie "Colombiana": "You never really finish a painting. You just stop working on it."

    There are two main reasons. Firstly my computer isn't that fast. Starbound really slows down when there are lots of things (entities?) on screen. I'm usually playing with x4 zoom because of that.
    Second reason is that my game loop is really long. It's about 40 ticks (you can count OR switches that are at the underwater section). I don't know how many wire-ticks per second Starbound calculates. I think it's slower then FPS but I can't say exact number.

    It's fun for in a weird way.
    Long time ago I've played Jagged Alliance 2. And it uses funny quiz kinda like in Fallout 3 or TES3: Morrowind to generate your character. When the game was translated (terrible, terrible adaptation) to my language one of the questions were "Least thing you want to do is..." and I used to pick "Programming". Because programming is boring, right? : ) As it turned out it's quite fun.
     
    MysticMalevolence likes this.
  20. Nibolas O Anelbozas

    Nibolas O Anelbozas Spaceman Spiff

    People like you is why one day i believe we'll have some cool sci-fi stuff, keep it up man, you are part of those that make human kind envolve.
     

Share This Page