diff options
author | rodri <rgl@antares-labs.eu> | 2023-09-01 12:44:38 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2023-09-01 12:44:38 +0000 |
commit | a764a5069421930c9261f87f02b0b4db3e80783b (patch) | |
tree | b5ee65d688d9da66ff7fb285086311d2dbf6fbaa | |
parent | 4f514003a8236aaeb9621b932c0f8329e03c1dd8 (diff) | |
download | battleship-a764a5069421930c9261f87f02b0b4db3e80783b.tar.gz battleship-a764a5069421930c9261f87f02b0b4db3e80783b.tar.bz2 battleship-a764a5069421930c9261f87f02b0b4db3e80783b.zip |
make playerq a fifo instead of a lifo.
-rw-r--r-- | btsd.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -34,8 +34,10 @@ popplayer(void) p = nil; qlock(&playerq); - if(playerq.nplayers > 0) - p = playerq.players[--playerq.nplayers]; + if(playerq.nplayers > 0){ + p = playerq.players[0]; + memmove(&playerq.players[0], &playerq.players[1], --playerq.nplayers * sizeof p); + } qunlock(&playerq); if(debug) fprint(2, "poppin fd %d sfd %d state %d\n", p->fd, p->sfd, p->state); @@ -49,8 +51,10 @@ nlpopplayer(void) Player *p; p = nil; - if(playerq.nplayers > 0) - p = playerq.players[--playerq.nplayers]; + if(playerq.nplayers > 0){ + p = playerq.players[0]; + memmove(&playerq.players[0], &playerq.players[1], --playerq.nplayers * sizeof p); + } if(debug) fprint(2, "poppin fd %d sfd %d state %d\n", p->fd, p->sfd, p->state); return p; @@ -135,6 +139,7 @@ battleproc(void *arg) threadcreate(netrecvthread, &cp[0], mainstacksize); threadcreate(netrecvthread, &cp[1], mainstacksize); + /* TODO ask for the username */ write(m->pl[0]->fd, "layout\n", 7); write(m->pl[1]->fd, "layout\n", 7); m->pl[0]->state = Outlaying; @@ -164,6 +169,7 @@ battleproc(void *arg) for(j = 0; j < nelem(coords); j++){ cell = coords2cell(coords[j]); orient = coords[j][strlen(coords[j])-1] == 'h'? OH: OV; + /* TODO keep track of the ships and report back on the first shot and when sunk */ settiles(p, cell, orient, shiplen(j), Tship); } p->state = Waiting; |