Deutsch   English   Français   Italiano  
<vhl32r$66a2$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Janis Papanagnou <janis_papanagnou+ng@hotmail.com>
Newsgroups: comp.lang.c
Subject: Re: logically weird loop
Date: Wed, 20 Nov 2024 17:34:34 +0100
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <vhl32r$66a2$1@dont-email.me>
References: <0e1c6d2e74d44a715bf7625ca2df022d169f878a@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 20 Nov 2024 17:34:36 +0100 (CET)
Injection-Info: dont-email.me; posting-host="d6931572e012e85d862a5804b94731cd";
	logging-data="203074"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18hh7zPnMY3dJspprtx9tSc"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
 Thunderbird/45.8.0
Cancel-Lock: sha1:PKk/Qw2GAfEYvVmGMVAzUaCnELk=
In-Reply-To: <0e1c6d2e74d44a715bf7625ca2df022d169f878a@i2pn2.org>
X-Enigmail-Draft-Status: N1110
Bytes: 3401

On 20.11.2024 16:56, fir wrote:
> i coded soem roguelike game loop which gave me
> a lot of logical trouble
> 
> imagine game has micro turns, thise micro turns are
> noted by
> int game_time = 0; //styart with microturn 0
> 
> if you press a key on keyboard you update variable
> of chuman character: character[HUM}.action_end = game_time+300
> then the not human bits should execute in thise microturns
> until you reacg turn 300 then you need to read keyboard again
> 
> what work is terribly weird, maybe becouse i started
> with while loop and while loops from my experience
> im not sure but imo tent do be logically heavy problematic
> form tiem to time..what work is

While loops are no more problematic than any other standard
control structure with as simple an operational semantics.

> 
> void ProcessMicroturnsUntilHuman()
>  {
>     if( game_time < character[HUM].action_end)
>     {
>      while(game_time < character[HUM].action_end)
>      {
>          DispatchActions();
>           game_time++;
>      }
>      if(game_time == character[HUM].action_end)     //**
>         DispatchActions();
>     }
> 
>  }

(I recall to have seem exactly such a code pattern (i.e. the
'if <', 'while <', 'if =') about 40 years ago in an university
exercise, so I suppose that structure is an effect of a valid
algorithm structure property. - But that just aside. It may
soothe you.)

What I really suggest - and sorry for not literally answering
your question - is to implement (for your roguelike) an event
queue where you schedule not only your human player's actions,
but also the monsters, and other timed events in the game. I'm
aware that this might mess up your plans but I think it will
pay to have a cleaner "simulation structure", also with better
decoupling properties.[*]

> 
> is there some more proper form of this loop?
> (the line nioted by ** i know is not needed but
> overally this loop is weird imo

It looks not nice, indeed. But code structure follows demands.
And, at first glance, I see no better structural variant with
loops and conditionals.

Janis


[*] A friend of mine just recently implemented the code frame
for a roguelike and followed the suggestion of an event based
object-oriented implementation; it worked well, he told me.