31
8
My parents-in-law have a fishpond in their yard, filled with koi. It didn't really cross my mind until I noticed the following extract from my code.
',') & '_'
... I had fish-faces looking back at me from my screen...
Which has given me a great idea...
My quest for you, my dear golfers is to create a one-line ASCII aquarium, with the following rules:
- The size of the aquarium from side of the tank to the other side of the tank should be no smaller than 60 characters and no bigger than 80 characters. Sides of the tank need to be indicated using the pipe/bar (
|
) character. - Fish must be able to "swim" left to right between the sides of the tank. As they will be turning, a front view is required for the transition from one direction to the other.
The fish must look like the following:
}}< }} ',')
Fish swimming right(',' {{ >{{
Fish swimming left}}('_'){{
Fish facing the front
When a fish turns to change direction (30% chance), it must start from one direction, face the front, then face the other direction... Make sure there is ample room for the fish to turn, i.e. requires six spaces before the edge of the tank minimum...
- Unless a fish is blowing a bubble or changing direction, it will continue in the direction it is facing, if it gets within six spaces of the side of the tank, it will change direction.
- The fish (facing left or right) can on occasion (10% chance) stop to blow bubbles in succession (
.oO*
), so the fish is required to have a space available next to them in order for the bubble to exist, so a fish can only swim as close to the sides, save one space. The bubble must disappear before the fish can move on...
A series of example lines of the fish's behavior, with -
characters indicating the spaces, as the code display feature on here is a little strict... I will expect these dashes to be replaced with spaces when you code this...
Each line here could be considered a frame in time-lapse.
|-}}< }} ',')----------|
|--}}< }} ',')---------|
|---}}< }} ',')--------|
|----}}< }} ',')-------|
|-----}}< }} ',')------|
|-----}}< }} ',').-----|
|-----}}< }} ',')o-----|
|-----}}< }} ',')O-----|
|-----}}< }} ',')*-----|
|---------}}('_'){{----|
|-----------(',' {{ >{{|
|----------(',' {{ >{{-|
|---------(',' {{ >{{--|
|--------.(',' {{ >{{--|
|--------o(',' {{ >{{--|
|--------O(',' {{ >{{--|
|--------*(',' {{ >{{--|
|--------(',' {{ >{{---|
|-------(',' {{ >{{----|
|------(',' {{ >{{-----|
etc. The above example is, as I said, small, but you get the general idea...
Shortest code wins...
I am expecting the output on the same line (if possible), if not, displaying frame after frame in succession is fine... Whether you go one line or multiple lines is up to you. If you are doing multiple lines, they must be separated by a newline.
Also a timer is imposed between frames, 2000ms . This is mandatory.
Let's see what you've got!
If the fish gets too close to the edge of the aquarium, is it required to turn, or it may phase out of the screen? Must it be possible that the fish blows bubbles in this situation? Also, must it be possible (or is it forbidden, or is allowed but not required) for the fish to blow bubbles twice in succession? – John Dvorak – 2014-01-16T06:04:52.857
Are we allowed to leave old frames on the screen? If not, then the set of languages able to compete is rather limited. – John Dvorak – 2014-01-16T06:07:43.623
@JanDvorak Just quoting the bullet point I made: "Unless a fish is blowing a bubble or changing direction, it will continue in the direction it is facing, if it gets within six spaces of the side of the tank, it will change direction."
So if it gets within six spaces of the side of the tank it is required to change direction. It is also possible that a fish may blow bubbles twice... – WallyWest – 2014-01-16T06:09:00.083
OK, thanks. Golfscript is out due to the timing requirements, so, which language should I choose? :-) – John Dvorak – 2014-01-16T06:10:30.203
@JanDvorak Old frames can be left on the screen, I have updated my OP accordingly... I would suggest anything with a timing capability ;) JavaScript, PHP, PERL, C, etc. – WallyWest – 2014-01-16T06:12:52.770
Javascript was my first idea, but the timing makes a bit of overhead... – John Dvorak – 2014-01-16T06:14:04.707
Okay, I may have to alter this considerably... – WallyWest – 2014-01-16T06:14:59.810
@JanDvorak Okay, I have changed this to 100 frames of the aquarium's output...
You reckon GolfScript can still be used? – WallyWest – 2014-01-16T06:17:12.103
1Wait, no, don't do changes like this! I've already started coding! Would you mind rolling back? – John Dvorak – 2014-01-16T06:29:37.173
5
Please use the sandbox the next time.
– John Dvorak – 2014-01-16T06:32:16.673Really? I wanted this to be simpler for everyone... You were right, setting a timer is too much overhead...
I can't leave GolfScript in the corner... – WallyWest – 2014-01-16T06:32:35.933
@JanDvorak I'll remember the sandbox for next time, promise. – WallyWest – 2014-01-16T06:33:44.030
Uh, no, most languages can just do
sleep(2)
or a similar (and this would be the first time I use a function while golfing, and i like it). And Golfscript deserves to be left out. – John Dvorak – 2014-01-16T06:34:04.667Dammit... Okay, I'll roll it back... About time we had a real code golf challenge... – WallyWest – 2014-01-16T06:35:24.227
Thanks :-) (be sure to include the information that old frames can be left on the screen but they must be separated by a newline) – John Dvorak – 2014-01-16T06:37:11.420
Done! You're right, I should have sandboxed this first! LOL – WallyWest – 2014-01-16T06:39:02.723
1It's not explicitly stated, but I guess there must be exactly one fish in the aquarium? – John Dvorak – 2014-01-16T07:08:11.787
How is the size of the aquarium counted? The count of the hyphens + fish-chars in the middle? Wall-to-wall distance? 60..80 characters including the walls? – John Dvorak – 2014-01-16T07:12:29.110
@JanDvorak I assume including the walls. – Justin – 2014-01-16T07:20:10.353
@JanDvorak One fish only; it's easier ;)
Also one side of the tank counts as character 1, and the other side of the tank is x where x is a number between 60 and 80 (inclusive) – WallyWest – 2014-01-16T07:21:40.867
Amazing, so my aquarium is within tolerance :-) Now to get the fish moving :-) – John Dvorak – 2014-01-16T07:23:33.737
So yes, including walls! ;) – WallyWest – 2014-01-16T07:24:51.223
1Is it required that the fish may bubble twice in succession, or are we allowed to let it happen? It makes a three-character difference for me. – John Dvorak – 2014-01-16T07:42:56.537
Hmmm, it's okay if it bubbles twice, but like I said, but if it bubbles once, then moves and bubbles again, that's okay too. Just go with your gut @JanDvorak – WallyWest – 2014-01-16T07:57:02.777
"the bubble must disappear before the fish can move on" but in your example there's no frame where the bubble is gone and the fish hasn't moved. Which one is true, or are we allowed to do either? – John Dvorak – 2014-01-16T08:21:54.667
@Eliseod'Annunzio Would you consider having either the timer or n frames of output? I'm working on a SQL version. – SQB – 2014-01-16T08:40:34.473
@JanDvorak I'd say the bubble must have completed before the fish can move. – SQB – 2014-01-16T08:42:15.557