From 729e1085ee9178889d4b57665bb7a296e289bc73 Mon Sep 17 00:00:00 2001 From: Chris Mekelburg Date: Wed, 4 Dec 2024 21:45:52 -0500 Subject: [PATCH] update, need help with man.py generate_new_snack --- gamefiles/__pycache__/man.cpython-312.pyc | Bin 2252 -> 3472 bytes gamefiles/__pycache__/mine.cpython-312.pyc | Bin 559 -> 559 bytes gamefiles/__pycache__/score.cpython-312.pyc | Bin 0 -> 529 bytes gamefiles/__pycache__/snack.cpython-312.pyc | Bin 560 -> 560 bytes gamefiles/helpers.py | 8 +++-- gamefiles/man.py | 38 ++++++++++++++++---- gamefiles/mine.py | 2 ++ gamefiles/nav_game.py | 14 ++++---- gamefiles/score.py | 15 ++++++++ gamefiles/snack.py | 1 + 10 files changed, 61 insertions(+), 17 deletions(-) create mode 100644 gamefiles/__pycache__/score.cpython-312.pyc create mode 100644 gamefiles/score.py diff --git a/gamefiles/__pycache__/man.cpython-312.pyc b/gamefiles/__pycache__/man.cpython-312.pyc index 15a150b21ef3bc446a67b7c41d5898b5341d3091..0ba46696274e4dfcfb10899e853b4982581bfa9f 100644 GIT binary patch delta 1824 zcmZ`(&2Jk;6rb7MS+DJQ<0NZ)ow&gz31OQi4XC1}EkU8Qg+dCYf`g^jva%b;snikv96^Y`0FdgYRjpMj<5K3DRf(yJ^CuvDxR`cfV z`Tf?wW=BRPrvi3I&;Qia=RH|Nm2@h58_NjiPiuTb2=~HP@`Al9_6RXKRv%)8#^&O~5p(>m;x^V@7MTp;+58edE zSryOidm0#*j281n>heZGhdO&1b%NYtuE`|zlIa7!-0#P*in-U?*1ATOiS8bTMjM{ERe^u{AL5YI)vj3<1Xx{cMD5rk>3%#S@% z;ma`rUG5W58J|M54GcBGB{WmW8ZNnz)9rCr95-^=aoZI$lanl8!OPe6PZq75ohueB z7w23&VX;V(Fud&DmaJi?Gx>aa%d8Y(Se$uGeiZzy7l6#5daF|Lue3xzK7S=q8D5FB zFFbeU^enE2k4Mq2bsn{Lu8Sxfzb>hb(qZQ$uLORD&E^o? zXAD=q<1n@v#NH_5O_<;*zyKt9s3~)-8y@QIE%+uR)))Qw-xfM|7VZMwS>|-U1fHvLb~l=KPVG{NzokYejDT$o#;ZA6e?DB?gz}XTE;>hJ2u|?2XS4S6{6h`He@- zZQCuDUgU$q0KFDC?&N5-j|$kmt~7wPvPbqy?t+ zypxcU(>!UvFSV1w_5FzKzt8cc?S6oe_ygHTx*M*{;e^)Y2B~4w;y?zluqngI4KyTK zc=sDni_j5z(e!FSd%?tmoE~J{Ax1hF@xpkGaVp9IWzWE0(jl{`pU)dZ^bPoB&21e4 zvd&|S@1UOFMT8S~Q2QMetBcYMsr&phB3$ZLwJt~M;aEK!z2_$p?mBAuLq3dg_dUeu M`YW7@_jq~y10^Y(*8l(j delta 676 zcmYLGO=uHA6rS1Hzx+18ZcHks1ckLBZi85)QmKMJh#hPT{B`S#lFFkmY zghBMss|WESUIjrf9;zUM5EeX$r(Ptr2f>r`wp0h^oA15%&G&{kqteH8awn0961je~ z-Hof!akAjnW%QJA!fA`NX@gS270$TIHLh=~4MibW2sgF}H(x4vlaL1MN9^b>Qkw>e z6#)PKb+5m&;dOfBccqLb3xHZ%2@g=mKQB^8EYSHV*SAQ+>>IWzdUTbh#0UC-X2d1s zIh_%^N{yyPft{3@3v8ZR;tpGy%}J*wlW@3HNig1jM#X#fX09`g0UyRT%|pTe6RJaH zGb*M=PP|r^MM|qMHn7B7wJu(1c}sP}2L{^BrVk#Vv28#~eAg}~?Kq@m3?+o3aPq`8DTEb&@|St{LU*K``fx)F+9l zMdCTgi5=tdVnyl$t?9RX2$V!Z diff --git a/gamefiles/__pycache__/score.cpython-312.pyc b/gamefiles/__pycache__/score.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..300a28837b45197c23ee888f21d4822cfa4c496a GIT binary patch literal 529 zcmZ{hF;Buk6vy9PX-h@a0VHuSjCS#&uEs&#Oi0u)=+a>Cgj(9-9f%|ljKPGF&ClRx zadB`UtWIoA*qFR4GBEg({+j>&UhZA)KC{_1kj2f*Y6b!PsIV-VlbWfPcc3tUTj(Gg zyGx_A_V>-6lCCaL5ue)0Fhuiq}`XA-%rh&BPm_ zhM)#dc5I_UIJA*XPmu&Y27_9Q;Q#uHt*5oZ%CYz0o>g-i%}U?>*n zH>4~W7sRb`PXx?o^}80Yl5-~fX4D`-#rMLh)ApJ*$Bif>LEAkbt!! zm4Fe2d#}y}Nha+#Iy@^UBvAJyt|VSyY_1O8~^|S delta 22 ccmdnMvVn#7G%qg~0}xc4^GWa8$g9i*07E4O%K!iX diff --git a/gamefiles/helpers.py b/gamefiles/helpers.py index 3e175a1..60ff64c 100644 --- a/gamefiles/helpers.py +++ b/gamefiles/helpers.py @@ -1,12 +1,14 @@ #List of helper functions to move the man -def add(vec0, vec1): +'''def add(vec0, vec1): """Adds two vectors. Got tired of doing this by hand. """ x0, y0 = vec0 x1, y1 = vec1 return (x0 + x1, y0 + y1) +''' + def get_occupant(game, position): """Returns the agent at position, if there is one. @@ -18,7 +20,7 @@ def get_occupant(game, position): if position in positions_with_agents: agents_at_position = positions_with_agents[position] return agents_at_position[0] - +''' def distance(vec0, vec1): """Returns the distance between two vectors, using the "manhattan distance," or the distance if you can only @@ -27,4 +29,4 @@ def distance(vec0, vec1): """ x0, y0 = vec0 x1, y1 = vec1 - return abs(x1 - x0) + abs(y1 - y0) \ No newline at end of file + return abs(x1 - x0) + abs(y1 - y0)''' \ No newline at end of file diff --git a/gamefiles/man.py b/gamefiles/man.py index 7afa046..f2f3338 100644 --- a/gamefiles/man.py +++ b/gamefiles/man.py @@ -1,7 +1,11 @@ from retro.agent import ArrowKeyAgent #from retro.game import Game #from helpers import add, get_occupant - +from retro.game import Game +from random import shuffle +from snack import Snack +width=25 +height=25 direction_vectors = { "KEY_RIGHT": (1, 0), @@ -25,7 +29,10 @@ class Man: vector = direction_vectors[keystroke.name] self.try_to_move(vector, game) - '''Checks if a space is avialable to move''' + '''Checks if a space is avialable to move. Also adds 1 point if the space + contains a snack and then removes the snack. Deducts 10 points if the + space contains a mine. Checks that the score is not negative and if it + is, ends the game.''' def try_to_move(self, vector, game): x,y = self.position vx,vy = vector @@ -43,22 +50,39 @@ class Man: if obstacle.snack: game.state['Score'] += 1 game.remove_agent(agents[0]) - + self.generate_new_snack() else: - game.state['Score'] -= 1 + game.state['Score'] -= 10 game.remove_agent(agents[0]) - + if game.state['Score'] <0: + self.die(game) + else: + pass else: self.position = future_position + '''Indicates what happens when the game is over.''' def die(self,game): game.state["message"] = "Game Over" self.color = "black" game.end() - - + def get_all_positions(self): + positions=[] + for i in range(width): + for j in range(height): + positions.append((i,j)) + return positions + '''issue here, is_empty is not generating a coordinate positon, + but I am not sure why it is not''' + def generate_new_snack(self): + all_positions=self.get_all_positions() + shuffle(all_positions) + index =0 + while Game.is_empty(all_positions[index]) == False: + index = index + 1 + Snack(all_positions[index]) ''' def __init__(self, position): self.position = position diff --git a/gamefiles/mine.py b/gamefiles/mine.py index c564caf..53573cc 100644 --- a/gamefiles/mine.py +++ b/gamefiles/mine.py @@ -6,3 +6,5 @@ class Mine: def __init__(self,position): self.position = position + + \ No newline at end of file diff --git a/gamefiles/nav_game.py b/gamefiles/nav_game.py index a725171..47a3d9e 100644 --- a/gamefiles/nav_game.py +++ b/gamefiles/nav_game.py @@ -1,19 +1,19 @@ from retro.game import Game from board import Board +from score import num_mines + width = 25 height = 25 -num_snacks = 10 -num_mines = 10 -board = Board(width,height,num_snacks,num_mines) -score = 0 state= {"Score":0} -#man = Man(board_size) +score =state["Score"] +num_snacks = 10 +num_mines = num_mines(score) +board = Board(width,height,num_snacks,num_mines) + game = Game( board.get_agents(num_snacks, num_mines), state, board_size = (width, height) ) -#print(board.get_agents()) -print(len(board.get_agents(10,10))) game.play() \ No newline at end of file diff --git a/gamefiles/score.py b/gamefiles/score.py new file mode 100644 index 0000000..f8ce62d --- /dev/null +++ b/gamefiles/score.py @@ -0,0 +1,15 @@ + + +def num_mines(score): + if score < 5: + num_mines = 10 + if 10 <= score <50: + num_mines = 20 + if 50 <= score <75: + num_mines = 30 + if 75 <= score <100: + num_mines = 40 + #else: + #num_mines = 50 + return num_mines + \ No newline at end of file diff --git a/gamefiles/snack.py b/gamefiles/snack.py index 6b75dd2..cb33e37 100644 --- a/gamefiles/snack.py +++ b/gamefiles/snack.py @@ -6,3 +6,4 @@ class Snack: def __init__(self,position): self.position = position +