Skip to content

E2E Test #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Sep 22, 2024
Merged

E2E Test #79

merged 30 commits into from
Sep 22, 2024

Conversation

miketwo
Copy link
Collaborator

@miketwo miketwo commented Sep 18, 2024

I made a test that plays the game using mostly random inputs and I made it so that it runs the test 10 times. It's exposing lots of bugs.

I fixed one of the harder ones with the message bus -- it would act weird if a nested publish() was called.

The other problems we'll have to work through together. If you have VSCode set up to run tests, it'll look like this:

image

@miketwo miketwo requested a review from vesper-arch September 18, 2024 02:21
It was erasing text instead of coloring it orange.
@vesper-arch
Copy link
Owner

I do not have vscode set up. There might be some kind of tool that does something similar (I run the test in the terminal currently)

@vesper-arch
Copy link
Owner

I'll try and get some work done on this once I get out of school

@miketwo
Copy link
Collaborator Author

miketwo commented Sep 18, 2024

Chiseling away.

Did you want self.buffs to be a list of Effects? It looks like it was originally a dict, and still gets set to be a dict by a bunch of Enemy's powers={...} in their init.

A list makes more sense, because ordering can be preserved, but you'll have to handle duplicates manually.

@vesper-arch
Copy link
Owner

Yeah a list is what the new system will require since the previous one was a giant dictionary of every possible buff/debuff the player or enemy could have and all of them were set to 0 or false by default. Struggling with the new implementation though.

@miketwo
Copy link
Collaborator Author

miketwo commented Sep 19, 2024

Ok, I'll see what I can do. But if it's not understandable, we can always go back. This is a pet project -- it doesn't have to be coded perfectly. :-p

@miketwo
Copy link
Collaborator Author

miketwo commented Sep 19, 2024

The main issue here is that BEFORE_ATTACK is published from two places -- the player's attack() method and the enemy's attack() method, and they don't pass the same thing. For the player it passes the card object, who's damage can be modified before being used. But for the enemy it just passes the dmg and target.block -- basic integers which can't be modified by the function that's receiving them. In Python, passed objects can be modified, but basic types (like ints, floats, and strings) can't.

Example

def modify_value(value):
  value += 10

my_value = 5
print(f"Value Before: {my_value}")
modify_value(my_value)
print(f"Value After: {my_value}")

#--------------------------------------------
def modify_obj(obj):
  obj.value += 10

class MyObj:
  def __init__(self, value):
    self.value = value

my_obj = MyObj(5)
print(f"Object.Value Before: {my_obj.value}")
modify_obj(my_obj)
print(f"Object.Value After: {my_obj.value}")

If you run this, you'll get:

Value Before: 5
Value After: 5
Object.Value Before: 5
Object.Value After: 15

Showing that the object can be modified but the integer can't.

Solution

So because of that, if you want something (like damage or block or health) to be modified, it has to be passed inside an object. That's why the player attack (using a card object) works but the enemy attack doesn't.
To fix this, we'll want to make both publish() methods publish the same thing -- the attacker, the target, and a modifiable object representing the damage of the attack.

Then, on the receiving end, we just need to do two things:

  • "Is the message for me?" (i.e. If my buff/debuff effect is for attackers, make sure the attacker matches. If it's for defenders, make sure the target matches)
  • "Adjust the damage" (depending on whether I'm a buff or debuff, and whether I'm on the attacker or defender, adjust the attack damage accordingly).

I'll take a first crack at it.

@miketwo
Copy link
Collaborator Author

miketwo commented Sep 20, 2024

Slow and steady. On the bright side, it looks like 2 out of the 10 end-to-end tests didn't crash. 👍

Effect must be an Effect class. You passed "Strength Down"
I missed a few things in the last commit. This commit finishes the job.
@miketwo
Copy link
Collaborator Author

miketwo commented Sep 22, 2024

Sometimes the tests pass, sometimes they don't. I think we still have a problem with randomness. But I got it to mostly work.

@miketwo miketwo marked this pull request as ready for review September 22, 2024 16:20
@vesper-arch vesper-arch merged commit 7a81921 into vesper-arch:main Sep 22, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants