Skip to content

Instantly share code, notes, and snippets.

@mcoolin
Created April 9, 2012 02:56
Show Gist options
  • Save mcoolin/2341081 to your computer and use it in GitHub Desktop.
Save mcoolin/2341081 to your computer and use it in GitHub Desktop.
-module(crw).
%% -import(random).
-export([start/0]).
-record( mappoint, { row=0,
col=0,
display_char='.',
occupying=[] %% contians all items at this point
}).
-record( carrot, { multiply=1,
display_char='c',
live=8,
speed=0,
direction=0,
minChildren=0,
maxChildren=24,
hear=0,
notify=0,
eat=0
}).
-record( rabbit, { multiply=2,
display_char='r', %% Preg rabbit will be R
live=48,
see=2,
speed=6,
direction=0,
minChildren=0,
maxChildren=8,
hear=4,
notify=5,
eat=2
}).
-record( wolf, { multiply=3,
display_char='w', %% Preg wolf will be W
live=60,
speed=5,
direction=0,
minChildren=0,
maxChildren=8,
see=4,
hear=5,
notify=8,
eat=3
}).
create_carrot() ->
#carrot{}.
create_wolf() ->
#wolf{}.
create_mappoint() ->
#mappoint{}.
create_mappoint(Row, Col) ->
RN = random:uniform(10),
if RN == 7 ->
#mappoint{row=Row, col=Col, occupying=create_carrot()};
true ->
#mappoint{row=Row, col=Col}
end.
create_row() ->
array:new([{size,80}, {fixed,true}, {default,create_mappoint()}]).
create_world() ->
Ra = array:new([{size,24}, {fixed, true}]),
Rows = lists:seq(0, 23),
Cols = lists:seq(0, 79),
lists:foreach(
fun(R) ->
Ca = array:new([{size,79}, {fixed, true}]),
lists:foreach(
fun(C) ->
array:set(C, create_mappoint(R,C), Ca),
io:format("The mappoint is: ~p,~p, ~w.~n", [R,C, Ca])
end,
Cols),
array:set(R, Ca, Ra)
end,
Rows).
%% array:new([{size,24}, {fixed, true}, {default, create_row()}]).
show_row() ->
show_row(0).
show_row(N) ->
if N < 80 ->
io:format('.'),
show_row(N+1);
true ->
io:nl()
end.
show_world() ->
World = create_world(),
SampleWolf = create_wolf(),
io:format("The value is: ~p.~n", [World]),
show_row(),
io:nl().
initialize() ->
io:format("Initialize world array!~n").
start() ->
random:seed(erlang:now()),
show_world(),
tick(),
stop().
stop() ->
io:format("Something won!~n").
tick() ->
io:format("Send out a system tick~n").
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment