Skip to content

Commit

Permalink
MAINT: Apply 'pre-commit run --all' and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Mar 10, 2022
1 parent ddacedb commit e7520d6
Show file tree
Hide file tree
Showing 22 changed files with 199 additions and 230 deletions.
1 change: 0 additions & 1 deletion 00_Common/BASIC_Tests/InputTest.bas
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
20 PRINT "You entered: ";A;B;C
30 PRINT "--------------------------"
40 GOTO 10

2 changes: 0 additions & 2 deletions 00_Common/BASIC_Tests/OutputTest.bas
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
10 A=1: B=-2: C=0.7: D=123456789: E=-0.0000000001
20 PRINT "|";A;"|";B;"|";C;"|";D;"|";E;"|"


2 changes: 0 additions & 2 deletions 00_Common/BASIC_Tests/RndTest.bas
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@
20 PRINT "2: ";RND(-2);RND(1);RND(1);RND(1)
30 PRINT "3: ";RND(-5);RND(1);RND(1);RND(1)
40 PRINT "4: ";RND(-2);RND(1);RND(1);RND(1)


Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ private static float Scale(float zeroToOne, float inclusiveMinimum, float exclus
}

private static int ToInt(float value) => (int)Math.Floor(value);
}
}
2 changes: 1 addition & 1 deletion 00_Common/dotnet/Games.Common/_InternalsVisibleTo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
using System.Runtime.CompilerServices;

[assembly:InternalsVisibleTo("Games.Common.Test")]
[assembly:InternalsVisibleTo("Games.Common.Test")]
9 changes: 4 additions & 5 deletions 00_Utilities/mardown_todo_rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::fs::metadata;
use std::path::{Path, PathBuf};
/**
* todo list generator for this repository, coded in rust
*
* @author Anthony Rubick
*
* @author Anthony Rubick
*/


Expand Down Expand Up @@ -40,7 +40,7 @@ fn main() {
");


//ask user how they want the todo list formatted
format_game_first = get_yn_from_user("\n\t---====FORMATS====---\ngame first:\n\tGame\n\t\tLanguage ✅/⬜️\n\nlang first:\n\tLanguage\n\t\tGame ✅/⬜️\n\nmake todo list using the game first format? (y/n | default No) ");

Expand Down Expand Up @@ -214,7 +214,7 @@ fn get_yn_from_user(prompt:&str) -> bool {

//default in case of error
if input.is_empty() {return false;}

//get and parse input
match &input[0..1] { //get first character
"y" | "Y" => return true,
Expand Down Expand Up @@ -243,4 +243,3 @@ fn _list_files(vec: &mut Vec<PathBuf>, path: &Path) {
}
}
}

1 change: 0 additions & 1 deletion 01_Acey_Ducey/lua/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ As published in Basic Computer Games (1978), as found at Annarchive:

Conversion to Lua
- [Lua.org](https://www.lua.org)

2 changes: 1 addition & 1 deletion 02_Amazing/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"
rand = "0.8.5"
2 changes: 1 addition & 1 deletion 02_Amazing/rust/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)

Conversion to [Rust](https://www.rust-lang.org/) by Anthony Rubick [AnthonyMichaelTDM](https://github.com/AnthonyMichaelTDM)
Conversion to [Rust](https://www.rust-lang.org/) by Anthony Rubick [AnthonyMichaelTDM](https://github.com/AnthonyMichaelTDM)
18 changes: 9 additions & 9 deletions 02_Amazing/rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ fn main() {
/*
vector of:
vectors of:
integers
Initially set to 0, unprocessed cells.
integers
Initially set to 0, unprocessed cells.
Filled in with consecutive non-zero numbers as cells are processed
*/
let mut used; //2d vector
/*
vector of:
vectors of:
integers
integers
Remains 0 if there is no exit down or right
Set to 1 if there is an exit down
Set to 2 if there is an exit right
Expand All @@ -43,11 +43,11 @@ fn main() {
let width;
let height;
let entrance_column; //rng, column of entrance
let mut row;
let mut row;
let mut col;
let mut count;



//print welcome message
println!("
Expand Down Expand Up @@ -171,13 +171,13 @@ fn main() {
fn get_user_input(prompt: &str) -> usize {
//DATA
let mut raw_input = String::new(); // temporary variable for user input that can be parsed later

//input loop
return loop {

//print prompt
println!("{}", prompt);

//read user input from standard input, and store it to raw_input
raw_input.clear(); //clear input
io::stdin().read_line(&mut raw_input).expect( "CANNOT READ INPUT!");
Expand All @@ -186,7 +186,7 @@ fn get_user_input(prompt: &str) -> usize {
match raw_input.trim().parse::<usize>() {
Ok(i) => {
if i>1 { //min size 1
break i; // this escapes the loop, returning i
break i; // this escapes the loop, returning i
}
else {
println!("INPUT OUT OF RANGE. TRY AGAIN.");
Expand Down
142 changes: 63 additions & 79 deletions 04_Awari/python/awari.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,85 +6,69 @@
Ported by Dave LeCompte
"""

"""
PORTING NOTES
This game started out as 70 lines of BASIC, and I have ported it
before. I find it somewhat amazing how efficient (densely packed) the
original code is. Of course, the original code has fairly cryptic
variable names (as was forced by BASIC's limitation on long (2+
character) variable names). I have done my best here to interpret what
each variable is doing in context, and rename them appropriately.
I have endeavored to leave the logic of the code in place, as it's
interesting to see a 2-ply game tree evaluation written in BASIC,
along with what a reader in 2021 would call "machine learning".
As each game is played, the move history is stored as base-6
digits stored losing_book[game_number]. If the human player wins or
draws, the computer increments game_number, effectively "recording"
that loss to be referred to later. As the computer evaluates moves, it
checks the potential game state against these losing game records, and
if the potential move matches with the losing game (up to the current
number of moves), that move is evaluated at a two point penalty.
Compare this, for example with MENACE, a mechanical device for
"learning" tic-tac-toe:
https://en.wikipedia.org/wiki/Matchbox_Educable_Noughts_and_Crosses_Engine
The base-6 representation allows game history to be VERY efficiently
represented. I considered whether to rewrite this representation to be
easier to read, but I elected to TRY to document it, instead.
Another place where I have made a difficult decision between accuracy
and correctness is inside the "wrapping" code where it considers
"while human_move_end > 13". The original BASIC code reads:
830 IF L>13 THEN L=L-14:R=1:GOTO 830
I suspect that the intention is not to assign 1 to R, but to increment
R. I discuss this more in a porting note comment next to the
translated code. If you wish to play a more accurate version of the
game as written in the book, you can convert the increment back to an
assignment.
I continue to be impressed with this jewel of a game; as soon as I had
the AI playing against me, it was beating me. I've been able to score
a few wins against the computer, but even at its 2-ply lookahead, it
beats me nearly always. I would like to become better at this game to
explore the effectiveness of the "losing book" machine learning.
EXERCISES FOR THE READER
One could go many directions with this game:
- change the initial number of stones in each pit
- change the number of pits
- only allow capturing if you end on your side of the board
- don't allow capturing at all
- don't drop a stone into the enemy "home"
- go clockwise, instead
- allow the player to choose to go clockwise or counterclockwise
- instead of a maximum of two moves, allow each move that ends on the
"home" to be followed by a free move.
- increase the AI lookahead
- make the scoring heuristic a little more nuanced
- store history to a file on disk (or in the cloud!) to allow the AI
to learn over more than a single session
"""
# PORTING NOTES
#
# This game started out as 70 lines of BASIC, and I have ported it
# before. I find it somewhat amazing how efficient (densely packed) the
# original code is. Of course, the original code has fairly cryptic
# variable names (as was forced by BASIC's limitation on long (2+
# character) variable names). I have done my best here to interpret what
# each variable is doing in context, and rename them appropriately.
#
# I have endeavored to leave the logic of the code in place, as it's
# interesting to see a 2-ply game tree evaluation written in BASIC,
# along with what a reader in 2021 would call "machine learning".
#
# As each game is played, the move history is stored as base-6
# digits stored losing_book[game_number]. If the human player wins or
# draws, the computer increments game_number, effectively "recording"
# that loss to be referred to later. As the computer evaluates moves, it
# checks the potential game state against these losing game records, and
# if the potential move matches with the losing game (up to the current
# number of moves), that move is evaluated at a two point penalty.
#
# Compare this, for example with MENACE, a mechanical device for
# "learning" tic-tac-toe:
# https://en.wikipedia.org/wiki/Matchbox_Educable_Noughts_and_Crosses_Engine
#
# The base-6 representation allows game history to be VERY efficiently
# represented. I considered whether to rewrite this representation to be
# easier to read, but I elected to TRY to document it, instead.
#
# Another place where I have made a difficult decision between accuracy
# and correctness is inside the "wrapping" code where it considers
# "while human_move_end > 13". The original BASIC code reads:
#
# 830 IF L>13 THEN L=L-14:R=1:GOTO 830
#
# I suspect that the intention is not to assign 1 to R, but to increment
# R. I discuss this more in a porting note comment next to the
# translated code. If you wish to play a more accurate version of the
# game as written in the book, you can convert the increment back to an
# assignment.
#
# I continue to be impressed with this jewel of a game; as soon as I had
# the AI playing against me, it was beating me. I've been able to score
# a few wins against the computer, but even at its 2-ply lookahead, it
# beats me nearly always. I would like to become better at this game to
# explore the effectiveness of the "losing book" machine learning.
#
#
# EXERCISES FOR THE READER
# One could go many directions with this game:
# - change the initial number of stones in each pit
# - change the number of pits
# - only allow capturing if you end on your side of the board
# - don't allow capturing at all
# - don't drop a stone into the enemy "home"
# - go clockwise, instead
# - allow the player to choose to go clockwise or counterclockwise
# - instead of a maximum of two moves, allow each move that ends on the
# "home" to be followed by a free move.
# - increase the AI lookahead
# - make the scoring heuristic a little more nuanced
# - store history to a file on disk (or in the cloud!) to allow the AI
# to learn over more than a single session


game_number = 0
Expand Down
Loading

0 comments on commit e7520d6

Please sign in to comment.