Skip to content

Conversation

@tsmaster
Copy link
Contributor

I attempted to do a faithful port of the logic for the most part. In particular, there's a clever base-6 encoding of move history that allows games to be stored as integers in a "losing book" array, which allows the AI to become stronger over time. I did not change this logic, as I felt that the cleverness of this solution is worth observing. I endeavored to make every variable clearer, and use functions to help make program flow easier to understand.

I did make one small change to the logic, which I also documented clearly, having to do with evaluating very large moves. The code, as originally published, looks like a typo to me, but with BASIC, it's hard to be certain.

Also, I'm bad at this game; the computer beats me almost always.

I attempted to do a faithful port of the logic for the most part. In particular, there's a clever base-6 encoding of move history that allows games to be stored as integers in a "losing book" array, which allows the AI to become stronger over time. I did not change this logic, as I felt that the cleverness of this solution is worth observing. I endeavored to make every variable clearer, and use functions to help make program flow easier to understand.

I did make one small change to the logic, which I also documented clearly, having to do with evaluating very large moves. The code, as originally published, looks like a typo to me, but with BASIC, it's hard to be certain.

Also, I'm bad at this game; the computer beats me almost always.
@coding-horror
Copy link
Owner

Sure -- I could go either way but "de-clevering" is probably better long term -- the comments could point out the goal of the cleverness ;)

@coding-horror coding-horror merged commit f908e0c into coding-horror:main Mar 1, 2021
@tsmaster
Copy link
Contributor Author

tsmaster commented Mar 1, 2021

Sure -- I could go either way but "de-clevering" is probably better long term -- the comments could point out the goal of the cleverness ;)

Yeah, I thought about this for a while, and considered three paths:

  1. leave the clever implementation more or less as-is, but with documentation. This would preserve the implementation as a historical artifact

  2. modify the implementation to be more idiomatic, perhaps with documentation talking about the old code.

  3. rewrite it from scratch

I think, if I was trying to write maintainable, extensible code, I'd go with #3, rewriting from scratch. But Indiana Jones' voice "this should be in a museum" convinced me to go with #1, preservation and documentation. For now.

I'm currently in the middle of "POETRY", which is a pretty gnarly mess of spaghetti. It'll be interesting to see what shape it's in when I'm done. Which I mention as a means of saying that I expect the Awari history cleverness to be the exception, not the rule.

@coding-horror
Copy link
Owner

Absolutely! Probably the best thing to do is capture the intent in the comments so the next person who looks at it can decode the cleverness ;)

@tsmaster tsmaster deleted the port-awari branch March 1, 2021 04:41
@tsmaster
Copy link
Contributor Author

tsmaster commented Mar 1, 2021

Absolutely! Probably the best thing to do is capture the intent in the comments so the next person who looks at it can decode the cleverness ;)

I've attacked this program before, having taking a copy of BASIC Computer Games with me on vacation. Friends thought that it was weird that I was translating BASIC to Python for fun, but I remember teasing apart a bunch of what was going on at that time, including the clever history encoding scheme.

I'd be up for doing a less literal translation, with more idiomatic Python, and data structures that are easier to comprehend the first time you look at them.

I'm also happy to add another couple paragraphs walking through the cleverness, but as it was, I had a page of comments at the top of the file, and I wanted to check something in. :)

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