Re: logically weird loop

Liste des GroupesRevenir à cl c  
Sujet : Re: logically weird loop
De : profesor.fir (at) *nospam* gmail.com (fir)
Groupes : comp.lang.c
Date : 20. Nov 2024, 18:30:06
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <fbe6358f0891b9257d731a66633b80c2b31606dc@i2pn2.org>
References : 1 2 3
User-Agent : Mozilla/5.0 (Windows NT 10.0; WOW64; rv:91.0) Gecko/20100101 Firefox/91.0 SeaMonkey/2.53.19
fir pisze:
Janis Papanagnou pisze:
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.)
>
  this solo looks weird imo
    while(game_time < character[HUM].action_end)
   {
          DispatchActions();
           game_time++;
   }
   DispatchActions();
 the fact that you need add a thing outside the while loop which is logically part of this loop.. i eman game_time after that must be
character[HUM].action_end and the DispatchActions(); need to be called
for that value too
 this looks sorta unnatural and my game not worked correctly until i find i must add that final   DispatchActions();
it means imo that this while loop is here not natural and being not natural it makes you probles when you need to debug (and even debug sorta hard) why this logic dont work
 also i must also add the previous if
it is   if( game_time < character[HUM].action_end) {}
to not allow all this code to re-enter when it finally
reaches game_time == character[HUM].action_end
 its all weird and unnatural..but is logically not easy to find better way (though i not thinked on this too much only noticed this is kinda
weird imo, and i thing its baddly writen here)
 
if someone has a trouble understandong that loop it may substitute
character[HUM].action_end by 300
the loop need to go thru all micro turns/tures from 0 to 300
inclusded and fire the bot 'starters' (where bts have timers on
warious random microturns to act and than put those starters
on some microturns in future)
then imaginee each pressing space turns that 300 up by another 300
and another portion of micro turns is fired/dispatched (im not sure if the word dispatch is fully proper here (weak english) but maybe)

 
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.
>
 

Date Sujet#  Auteur
20 Nov 24 * logically weird loop32fir
20 Nov 24 +- Re: logically weird loop1fir
20 Nov 24 `* Re: logically weird loop30Janis Papanagnou
20 Nov 24  +* Re: logically weird loop4fir
20 Nov 24  i`* Re: logically weird loop3fir
20 Nov 24  i `* Re: logically weird loop2fir
21 Nov 24  i  `- Re: logically weird loop1fir
21 Nov 24  `* Re: logically weird loop25Lawrence D'Oliveiro
21 Nov 24   +* Re: logically weird loop21Janis Papanagnou
21 Nov 24   i+* Re: logically weird loop6fir
21 Nov 24   ii`* Re: logically weird loop5fir
21 Nov 24   ii `* Re: logically weird loop4Janis Papanagnou
21 Nov 24   ii  `* Re: logically weird loop3fir
21 Nov 24   ii   `* Re: logically weird loop2Janis Papanagnou
22 Nov 24   ii    `- Re: logically weird loop1fir
22 Nov 24   i+* Re: logically weird loop9Lawrence D'Oliveiro
22 Nov 24   ii+- Re: logically weird loop1Janis Papanagnou
22 Nov 24   ii`* Re: logically weird loop7Michael S
22 Nov 24   ii +* Re: logically weird loop2fir
22 Nov 24   ii i`- Re: logically weird loop1fir
5 Dec 24   ii `* Re: logically weird loop4Tim Rentsch
5 Dec 24   ii  `* Re: logically weird loop3Janis Papanagnou
5 Dec 24   ii   `* Re: logically weird loop2David Brown
5 Dec 24   ii    `- Re: logically weird loop1Janis Papanagnou
5 Dec 24   i`* Re: logically weird loop5Tim Rentsch
5 Dec 24   i `* Re: logically weird loop4Janis Papanagnou
7 Dec 24   i  `* Re: logically weird loop3Tim Rentsch
7 Dec 24   i   `* Re: logically weird loop2Keith Thompson
8 Dec 24   i    `- Re: logically weird loop1Kaz Kylheku
22 Nov 24   `* Re: logically weird loop3fir
22 Nov 24    `* Re: logically weird loop2fir
24 Nov 24     `- Re: logically weird loop1fir

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal