From e615e99e75797ddae2d137f38e36da67634a867c Mon Sep 17 00:00:00 2001 From: Cory Date: Sat, 18 May 2024 22:40:01 -0400 Subject: [PATCH] I got all of the free spaces to determine the number of mine neighbors they have and change their characters correspondingly. --- __pycache__/free_space.cpython-312.pyc | Bin 1102 -> 6358 bytes __pycache__/mine.cpython-312.pyc | Bin 1130 -> 1518 bytes __pycache__/mine_spawner.cpython-312.pyc | Bin 2418 -> 2888 bytes free_space.py | 52 ++++++++++++++++++++++- mine.py | 11 ++++- mine_spawner.py | 11 +++-- 6 files changed, 68 insertions(+), 6 deletions(-) diff --git a/__pycache__/free_space.cpython-312.pyc b/__pycache__/free_space.cpython-312.pyc index 56776513b76e38b36d10f40d595776a85bf58b26..83010ca3395543344f11a715a49fde8d70ac6ace 100644 GIT binary patch literal 6358 zcmeHLT}%{L6uz@Ru*zvX%MmP#Go$a+(O_IuV$A2DQgek_OHg z)W&1UWFO{FKxLSS#Lo!CZx9&2Q84&Tg3)glO#VEv~h*9wULTqOLrhB%1pJd@g*)F%!6Cs8TYdANp6^xpVN`8CahZ9%JT(7 z9}Lu1V~Ah`b>Ngmdy7MXm=F

v zzOlB^wwbcM6OnY;vDxB}GOj&Crtj>p%*0vy%18?LQn+v=s8bUjkYkGeN})0gH!YXU zfQ`Z1$T4!h5SF?lfh5N$hm>%I?1@aFupsso<(vYZ--CV$RRlZV_Q9a(W}zxszX;HU zQWeR6Kt*9r?!KT66KFSgj@qc}Q*th^eQHt8fvYPiiM(9%>a^+~R^JZoctMvW!O+z} z2*^f`<;d1q)<}_gKF&-LY=ub_k)k^wldUl{0axNw;tUGP6fa`d2&n9_q7L{(FOBuF z3xMm5Xf!1sWPmzw!hYL6B8){xqqD{PruO`@|EK+#a@SzP&9fPM$*r~!5D=_58?I=lMZ0;56oAFwdh;5 z5zFhk-JsbH`gKCLL$JDTe?WdV-OHA+(lVS~SxOnq)g%eVuERiza~mT?FrutZe zu(odlSZTabXsMPYZTCFlt)w*~4DvPs;T5E;Bf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wqC9r9{jvr_{JO-^$btF>73tLuq%Ie-Q)usUwy5Jn#wUi~5En8j6 zR<~jCr2&f%wQc#msgmCHK>udR05s+N=AC!w| zr+H%h&b%Fs9E^qIQJMZJnO4b&A}1E|tUX=|GvP*pe)BESc=*nQ)GF7LBOPGEM$7>V bA^fQW(7Fdqd%(U2EWeNg_Q5ouHY4x{0+-{h delta 657 zcmZuuOKTHR6uxKfoym0Kv}v2fnT*LaF|nlSn2Zm^QfiCAVvsD{bx}c#1>*~*bV}jb}GmJE58S$w|6;hL4L*FWs z<@baiG{{1d`RkBK_2Ibs*X-?pCe=y8o9rbtlBSE zPx9wP21w%yUw(xhRt>TT+PCqUvNX=Bd*U8@;uM|dJoz;FJu->z&_zdA^xS?#u+D5- zg^pF|#-@9O>WlE7w)kRbK347+ 0: + self.display = True + + def name_me(self, named): + self.name = named + + def check_neighbors(self,game): + names_of_mines = ["mine0","mine1","mine2","mine3","mine4","mine5","mine6","mine7","mine8","mine9"] + if game.on_board((self.width + 1,self.height)): + if len(game.get_agents_by_position()[(self.width + 1,self.height)]) != 0: + if game.get_agents_by_position()[(self.width + 1,self.height)][0].name in names_of_mines: + self.neighbors = self.neighbors + 1 + if game.on_board((self.width - 1,self.height)): + if len(game.get_agents_by_position()[(self.width - 1,self.height)]) != 0: + if game.get_agents_by_position()[(self.width - 1,self.height)][0].name in names_of_mines: + self.neighbors = self.neighbors + 1 + if game.on_board((self.width,self.height + 1)): + if len(game.get_agents_by_position()[(self.width,self.height + 1)]) != 0: + if game.get_agents_by_position()[(self.width,self.height + 1)][0].name in names_of_mines: + self.neighbors = self.neighbors + 1 + if game.on_board((self.width,self.height - 1)): + if len(game.get_agents_by_position()[(self.width,self.height - 1)]) != 0: + if game.get_agents_by_position()[(self.width,self.height - 1)][0].name in names_of_mines: + self.neighbors = self.neighbors + 1 + if game.on_board((self.width + 1,self.height + 1)): + if len(game.get_agents_by_position()[(self.width + 1,self.height + 1)]) != 0: + if game.get_agents_by_position()[(self.width + 1,self.height + 1)][0].name in names_of_mines: + self.neighbors = self.neighbors + 1 + if game.on_board((self.width + 1,self.height - 1)): + if len(game.get_agents_by_position()[(self.width + 1,self.height - 1)]) != 0: + if game.get_agents_by_position()[(self.width + 1,self.height - 1)][0].name in names_of_mines: + self.neighbors = self.neighbors + 1 + if game.on_board((self.width - 1,self.height + 1)): + if len(game.get_agents_by_position()[(self.width - 1,self.height + 1)]) != 0: + if game.get_agents_by_position()[(self.width - 1,self.height + 1)][0].name in names_of_mines: + self.neighbors = self.neighbors + 1 + if game.on_board((self.width - 1,self.height - 1)): + if len(game.get_agents_by_position()[(self.width - 1,self.height - 1)]) != 0: + if game.get_agents_by_position()[(self.width - 1,self.height - 1)][0].name in names_of_mines: + self.neighbors = self.neighbors + 1 + if self.neighbors > 0: + self.character = str(self.neighbors) \ No newline at end of file diff --git a/mine.py b/mine.py index b8eefc9..4104325 100644 --- a/mine.py +++ b/mine.py @@ -15,4 +15,13 @@ class Mine: game.end() def hide(self): - self.display = False \ No newline at end of file + self.display = False + + def name_me(self, named): + self.name = named + + def check_neighbors(self,game): + pass + + def reveal(): + pass \ No newline at end of file diff --git a/mine_spawner.py b/mine_spawner.py index 3c25a27..eb66810 100644 --- a/mine_spawner.py +++ b/mine_spawner.py @@ -22,20 +22,23 @@ class Spawner: for i in range(self.board_width): for j in range(self.board_height): free_space = FreeSpace((i,j)) + free_space.name_me("freespace"+str(i)+str(j)) game.add_agent(free_space) # Then spawn 10 mines for i in range(10): mine = Mine(((randint(0, self.board_width - 1)),(randint(0, self.board_height - 1)))) - game.log(mine.position) + mine.name_me("mine"+str(i)) + game.log(str(mine.name) + " is located at " + str(mine.position)) # If there is a free space where a mine is going to be, remove the free space and then add the mine. if not game.is_empty(mine.position): game.remove_agent(game.get_agents_by_position()[mine.position][0]) game.add_agent(mine) - # Now ask all of the mines and free spaces to hide themselves. + # Now ask all free spaces to keep track of their neighbors that are mines + # and all of the mines and free spaces to hide themselves. for i in range(self.board_width): for j in range(self.board_height): if len(game.get_agents_by_position()[(i,j)]) != 0: + game.get_agents_by_position()[(i,j)][0].check_neighbors(game) game.get_agents_by_position()[(i,j)][0].hide() # Now create a cursor. - game.add_agent(Cursor((self.board_width - 1, self.board_height - 1))) - + game.add_agent(Cursor((self.board_width - 1, self.board_height - 1)))