Re: matrix.exe

Liste des GroupesRevenir à cl c  
Sujet : Re: matrix.exe
De : fir (at) *nospam* grunge.pl (fir)
Groupes : comp.lang.c
Date : 06. Apr 2024, 21:46:18
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <uus8q5$9jjp$1@i2pn2.org>
References : 1
User-Agent : Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
fir wrote:
>
>
yesterday i got nice remark related to
teh idea of "call queue" i described before
>
i will maybe remember that idea of call queue is
like that
>
void foo()
{
    for(int i=0; i<10;i++)
     queued f(i);
}
>
f(i) here abowe is not fired but each "call"
just stores a pointer to thsi function and argument
in "queue call" array - and the queue is then run
after the foo ends (or eventually maybe in some other
moment if that would be good) - the queue can be
called in sequential order but also could be
run in parralel covering multithreading in neat
form imo
>
what i noticed yesterday was like that:
>
i liek agent systems - i mean as i said also recently
the coding in is in good extent a metter of good coposition
and i find agents potentially as a very nice method
of composition
>
and here it shows if you have agent system you in fact
need something like call queue but not a temporal like
in those previose examples but permament i mean if
>
    for(int i=0; i<10;i++)
     queued f(i);
>
setups queue for 10 entries (each entry holds
function all) and you will not just execute whole queue
once and remove pointers but just execute it in loop
its good base for agent system
>
note you got 10 entries (agent update points) here and
each agents eventually could kill itself by removing
its pointer from the queue , also could like spawn
itself (by adding another cpointer to queue, like
increasing queue form 10 to 11 entries and so on)
>
so it is basic environment for such things as born, die,
spawn etc... i find it interesting..it seem to confirm
that the call queue idea is good and important thing
>
>
i started to think how i would write basic agent
system using that..posiibly queue should hold not only
update points but maybe also "state variables" of
given agent? im not sure - this is related
to thing i once wrote on this - imagine some simple
agent like say something which is drawed as a white
pixel on 2d black bitmap screen.. such agents could
be described by some entities (variables) that it has full
right to write by its own code but it also will be
described by some variables that shouldnt be
given for it to freally changed - as agents must
be managed by some "ruler" - and this is a whole side
topic to consider.. (not strictly the topic of
permement queue but somewhat partially also related
if the wuestion is how to design it all)
i can write such basic matrix lke that
#include<stdio.h>
#include "green-fire.h"
  int IsInsideFrame(int x, int y)
  {
     if(x<0|x>=frame_size_x|y<0|y>=frame_size_y) return 0;
     return 1;
  }
/////////
  typedef  void (*qp)(int) ;
  qp* permament_queue = NULL;
  int permament_queue_size = 0;
   void permament_queue_resize(int size)
   {
     permament_queue=(qp*)realloc(permament_queue, (permament_queue_size=size)*sizeof(qp));
   }
   void permament_queue_add(qp entry)
   {
      permament_queue_resize(permament_queue_size+1);
      permament_queue[permament_queue_size-1] = entry;
   }
   void RunPermamentQueue()
   {
     for(int i=0; i< permament_queue_size; i++)  permament_queue[i](i);
   }
///////////
   struct Agent {int x; int y;};
   Agent* agents = NULL;
   int agents_size = 0;
    void agents_resize(int size)
    {
      agents=(Agent*)realloc(agents, (agents_size=size)*sizeof(Agent));
    }
   void agents_add(int x, int y)
   {
      agents_resize(agents_size+1);
      agents[agents_size-1] = {x,y};
   }
/////////
  extern  void AgentEntryPoint(int whom);
  void CreateAgent(int x, int y)
  {
    permament_queue_add(AgentEntryPoint);
    agents_add(x,y);
  }
  ///////////////////////////
  void AgentEntryPoint(int who)
  {
    int new_x =  agents[who].x + rand2(-1,1);
    int new_y =  agents[who].y + rand2(-1,1);
    if(!IsInsideFrame) return;
    SetPixelSafe(agents[who].x, agents[who].y, 0x336633);
    agents[who] = {new_x, new_y};
    SetPixelSafe(agents[who].x, agents[who].y, 0xffffff);
  }
//  void DrawAgents()
//  {
//   for(int i=0; i<agents_size; i++)
//    SetPixelSafe(agents[i].x, agents[i].y, 0xffffff);
//
//  }
void CreateAgents()
{
   static int initialised = 0;  if(initialised) return;  initialised=1;
   for(int i=0; i<100; i++) CreateAgent(100+i*2,100);
}
void MouseMove(int x, int y) {}
void KeyDown(int key) {}
void RunFrame(int n)
{
   CreateAgents();
//  ClearFrameData(0);
   RunPermamentQueue();
//  DrawAgents();
}
void OnResize() { }
int main(int argc, char* argv[])
{
         RegisterMouseMove( MouseMove );
         RegisterKeyDown(  KeyDown );
         RegisterOnResize( OnResize );
         RegisterRunFrame( RunFrame );
         SetSleepValue(10);
         SetScaleOnResize(1);
         SetupWindow4(" MATRIX by fir (spring 2024) ",  10, 10, .9, .9, 300 );
         return 0;
}
back then i wanted to make something liek strategic game for this bots to fight but not get a much idea
some idea could be for example :
1) allow the agents to splity on parts or group into one (say one has 100 points (though this is kinda internal value as each one has always 1 pixel size) but can split  out on 100 1point  ot 3 x 30 points + one of 10 points and any possible way of dividing and gruping
2) the smaller move faster 1-points are fastest 100-point one is slowest
3) when two enemy ships met the stronger destroys the weaker
4) each one has limited radious of vision
5) they can collect food spred randomly over the map
6) the goal may be to localize enemy base and hit it with say 5 points
meybe something like that could give soem sane rules of "war"
i dont know
the idea is to make something interesting out of this but it not necessary must be interestuing sadly

Date Sujet#  Auteur
6 Apr 24 * matrix.exe7fir
6 Apr 24 +- Re: matrix.exe1fir
7 Apr 24 `* Re: matrix.tsk5Lawrence D'Oliveiro
7 Apr 24  `* Re: matrix.tsk4fir
7 Apr 24   `* Re: matrix.tsk3Lawrence D'Oliveiro
8 Apr 24    `* Re: matrix.tsk2fir
9 Apr 24     `- Re: matrix.tsk1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal