Skip to content
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

Separate agents from game logic #30

Merged
merged 1 commit into from
Feb 7, 2024
Merged

Separate agents from game logic #30

merged 1 commit into from
Feb 7, 2024

Conversation

paul90317
Copy link
Contributor

@paul90317 paul90317 commented Feb 6, 2024

In this commit, I split the original ttt.c, making it easier to add new agents. To achieve this, I also made the following changes:

  • Introduced move_t to make negamax a pure function.
  • Moved qsort out from available_moves to make it a part of the game logic.

Additionally, I declared table and move_record as static arrays because they are unnecessary to be dynamically allocated.

I also noticed #29, and I made some modifications to it without changing its score; specifically, I changed
is_consecutive(score, -1) to score < 0, and vice versa.

@paul90317 paul90317 force-pushed the temp branch 2 times, most recently from fcacab5 to 6ab9ffb Compare February 6, 2024 05:07
agents/negamax.c Outdated Show resolved Hide resolved
agents/negamax.h Show resolved Hide resolved
game_logic.h Outdated Show resolved Hide resolved
game_logic.h Outdated Show resolved Hide resolved
agents/negamax.c Outdated Show resolved Hide resolved
Copy link
Owner

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revise the git commit messages to reflect the reasons behind the proposed changes from a third-person perspective.

@paul90317 paul90317 force-pushed the temp branch 2 times, most recently from 7470f09 to e16a491 Compare February 7, 2024 04:40
agents/negamax.c Outdated Show resolved Hide resolved
game_logic.h Outdated Show resolved Hide resolved
In this commit, the original `ttt.c` was split to facilitate the
addition of new agents. Several changes were implemented to achieve
this:
1. `move_t` was introduced to transform `negamax` into a pure function
2. `qsort` was relocated from `available_moves` to incorporate it into
   the game logic.

The readability of the code also increases with the following
changes:
1. `table` and `move_record` were declared as static arrays.
2. The condition `is_consecutive(score, -1)` was replaced with
   `score < 0`, and vice versa.
@jserv jserv merged commit b87649d into jserv:main Feb 7, 2024
2 checks passed
@jserv
Copy link
Owner

jserv commented Feb 7, 2024

Thank @paul90317 for contributing. Next time, you should specify the meaningful name for git branch used by pull requests.

@paul90317 paul90317 deleted the temp branch February 7, 2024 13:47
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