sapphire-chess 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a152a756661a6bba522bd8a75bde7074e7386a5b65c1572225da5976acd86cd8
4
- data.tar.gz: 98c2040c722a85e5f5caf9a8dce9ee5caeb2bf1871b1b9dceb1e1d330de52e03
3
+ metadata.gz: 44df97bffb9cde364d3e734fc09129c0b0ffe860f8572ca47ed1cb304b121e2a
4
+ data.tar.gz: 61aa950fb118981973b8d1d58fe2ad1e4cd3e85dc8ad2c20fafdab16ef1a257b
5
5
  SHA512:
6
- metadata.gz: 108d87f43ba5f8c26f6e7e607dca07cbc57e7ae79ea4675b3649d5272995351b2cc37ca9570bac11651d4694b3978bba502b0ff60a1b52e5c30541ee68d77c41
7
- data.tar.gz: 7a035c86043ecec355bb910d834eec02c060f49705067b27ed2c5b9f467e5920e7adbf1bf215a31330fda448911797d4a8ded7e227b417bb96aa39832027bdcb
6
+ metadata.gz: 7dcdaf550d4b43871587ddacae31b28f1fe2b190732948a6db4a05423903769f16454eedf5aae3368b94e896497d96c014c96693c3b95fadfd660d1d3f377806
7
+ data.tar.gz: d5c4d34fda192846826a3c39eef7f06808918fad7e545dcc00e739be28ef37f48595dd62f3fae5b209c05502b48e01eedd089542c63841e0ce53a6f5efc6b482
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # 1.0.1 (January 16, 2023)
2
+
3
+ ## Enhancement:
4
+
5
+ - Remove useless assignments in `ai.rb`
6
+ - Fine tune pawn location values for not hard difficulties
7
+
8
+ ## Documentation:
9
+
10
+ - Update `README.md`
11
+ - Correct typo in `sapphire-chess.gemspec`
12
+
13
+
14
+ # 1.0.0 (January 15, 2023)
15
+
16
+ Initial irst release.
17
+
18
+ Please, visit https://medium.com/@lucas.sorribes/nostromo-my-ruby-chess-journey-part-i-7ef544b547a5 for a very detailed account of how I wrote this game.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sapphire-chess (1.0.0)
4
+ sapphire-chess (1.0.1)
5
5
  paint (~> 2.3)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,24 +1,62 @@
1
- # Sapphire Chess v0.9.0
1
+ # Sapphire Chess [![Gem Version](https://badge.fury.io/rb/sapphire-chess.svg)](https://badge.fury.io/rb/sapphire-chess)
2
2
 
3
- Welcome to Sapphire Chess!
4
-
5
- This is a chess game written in pure Ruby v2.7.5. Other versions have not been tested yet.
3
+ Sapphire Chess is a command line-based chess game with an algebraic notation input system,
4
+ complete chess rules, a beautiful interface and a functional AI. It provides three game modes:
5
+ Human vs. Human, Human vs. AI, and AI vs. AI.
6
6
 
7
7
  Please, visit https://medium.com/@lucas.sorribes/nostromo-my-ruby-chess-journey-part-i-7ef544b547a5 for a very detailed account of how I wrote this game.
8
8
 
9
+ Supported Rubies: 3.1, 3.0, 2.7.
10
+ The game has not been tested for older versions, but it might still work.
11
+
9
12
  ---
10
13
 
11
14
  ## Current Features
12
15
 
13
16
  * A beautiful board with easy-to-distinguish colors for white and black pieces.
14
17
  * Fully functional AI
15
- * Two game modes: human vs. computer, human vs. human.
16
18
  * Three levels of difficulty.
19
+ * Three game modes: human vs. computer, human vs. human.
17
20
  * Full chess movement rules implementation, including castling and *en passant*, for both the human and the computer player.
18
21
  * Accepts algebraic notation for movements, with human input validation.
19
22
  * Material score display.
20
23
  * Player's last move display.
21
24
 
25
+ ## Setup
26
+
27
+ Install with:
28
+ ```ruby
29
+ gem install 'saphhire-chess'
30
+ ```
31
+ And execute from the command prompt with:
32
+ ```
33
+ sapphire-chess
34
+ ```
35
+ Currently, the icons are only loaded properly from within VS Code terminals, so, for the moment, I highly recommend executing this command from there.
36
+
37
+ You can also create a new `.rb` file with this content and execute it:
38
+ ```ruby
39
+ require 'sapphire-chess'
40
+
41
+ Engine.new.play
42
+ ```
43
+
44
+ ## Difficulty Mode
45
+
46
+ The difficulty mode is based on how many turns the computer can think ahead (the depth of the tree generated by `AI#minimax`, max. 3), the aggressiveness of the pieces, and the enemy's carelessness.
47
+
48
+ My recommendation is to play the game on the *hard* mode, as this was the original intention when I designed it. I introduced the other difficulties based on the suggestions from those who weren't able to beat the machine. However, the hard mode, due to the current Minimax implementation, is a little slow; I'm working on ways to improve the performance of this method.
49
+
22
50
  ## Screenshot
23
51
 
24
- ![Game screenshot](./screenshot.png)
52
+ ![Game screenshot](https://live.staticflickr.com/65535/52630422741_bc858d0096_z.jpg)
53
+
54
+ ## The AI
55
+
56
+ The AI is based on a Minimax algorithm with Alpha-Beta pruning. This algorithm generates possible outcomes (*children*) for a provisional move: Each branch represents the enemy's possible move in the next turn as an answer to the provisional move; (i.e.: if current player is white [the maximizing player], it generates every possible movement for the next player, black [the minimizing player], who will choose the best possible move, and so on.
57
+
58
+ The best (relative to each player) possible outcome for each move will determine what move is chosen) The Alpha-Beta 'prunes' the tree: it makes the search more efficient, removing unnecessary branches, resulting in a faster process.
59
+
60
+ Copyright © 2023 Lucas Sorribes, released under the MIT license.
61
+
62
+
@@ -22,22 +22,11 @@ module AI
22
22
  move_randomizer(evaluations)
23
23
  end
24
24
 
25
+ # See README.md for an explanation of this method.
25
26
  def minimax(move, depth, alpha, beta, maximizing_player)
26
27
  return board.evaluate if depth.zero?
27
28
 
28
- move_final_evaluation =
29
29
  board.provisional(move, color) do
30
- # This generates possible outcomes (children) for the provisional move:
31
- # Each branch represents the next turn (i.e.: if current player is white
32
- # [the maximizing player], it generates every possible movement for the
33
- # next player, black [the minimizing player], who will choose the best
34
- # possible move, and so on. The best (relative to each player) possible
35
- # outcome for each move will determine what move is chosen, `best_evaluation`)
36
- # See AI#computer_chooses_move
37
-
38
- # The alpha-beta `prunes` the tree: it makes the search more efficient
39
- # removing unnecessary branches, resulting in a faster process.
40
- move_final_evaluation =
41
30
  if maximizing_player
42
31
  best_minimizing_evaluation = Float::INFINITY
43
32
 
@@ -62,8 +51,6 @@ module AI
62
51
  best_maximizing_evaluation
63
52
  end
64
53
  end
65
-
66
- move_final_evaluation
67
54
  end
68
55
 
69
56
  # This method randomizes the moves if two or more moves share the best evaluation.
@@ -43,7 +43,7 @@ class Pawn < Piece
43
43
  [50, 50, 60, 60, 60, 60, 50, 50],
44
44
  [50, 50, 60, 60, 60, 60, 50, 50],
45
45
  [50, 50, 60, 0, 0, 60, 50, 50],
46
- [50, 50, 10, 0, 0, 10, 50, 50],
46
+ [50, 40, 10, 0, 0, 10, 40, 50],
47
47
  [5, 10, 10, -20, -20, 10, 10, 5],
48
48
  [0, 0, 0, 0, 0, 0, 0, 0]
49
49
  ].freeze
@@ -51,7 +51,7 @@ class Pawn < Piece
51
51
  BLACK_LOCATION_VALUE_EASY = [
52
52
  [0, 0, 0, 0, 0, 0, 0, 0],
53
53
  [5, 10, 10, -20, -20, 10, 10, 5],
54
- [50, 50, 10, 0, 0, 10, 50, 50],
54
+ [50, 40, 10, 0, 0, 10, 40, 50],
55
55
  [50, 50, 60, 0, 0, 60, 50, 50],
56
56
  [50, 50, 60, 60, 60, 60, 50, 50],
57
57
  [50, 50, 60, 60, 60, 60, 50, 50],
@@ -1,3 +1,3 @@
1
1
  module SapphireChess
2
- VERSION ||= '1.0.0'
2
+ VERSION ||= '1.0.1'
3
3
  end
@@ -6,14 +6,14 @@ Gem::Specification.new do |spec|
6
6
  spec.summary = 'Command line-based chess game'
7
7
  spec.description = <<-EOF
8
8
  Sapphire Chess is a command line-based chess game with an algebraic notation input system,
9
- complete chess rules, a beautiful interface and a functional AI. It provides three game modes:
10
- Human vs. Human, Human vs. Ai, and AI vs. AI.
9
+ complete chess rules, a beautiful interface, and a functional AI. It provides three game modes:
10
+ Human vs. Human, Human vs. AI, and AI vs. AI.
11
11
  EOF
12
12
  spec.authors = ['Lucas Sorribes']
13
13
  spec.email = 'lucas.sorribes@gmail.com'
14
14
  spec.license = 'MIT'
15
15
  spec.homepage = 'https://github.com/lucsorr/sapphire-chess'
16
- spec.files = Dir['lib/**/*.rb'] + %w[Gemfile Gemfile.lock LICENSE Rakefile sapphire-chess.gemspec]
16
+ spec.files = Dir['lib/**/*.rb'] + %w[Gemfile Gemfile.lock LICENSE Rakefile sapphire-chess.gemspec CHANGELOG.md]
17
17
  spec.bindir = 'bin'
18
18
  spec.executables << 'sapphire-chess'
19
19
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sapphire-chess
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Sorribes
@@ -67,8 +67,8 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.4'
69
69
  description: " Sapphire Chess is a command line-based chess game with an algebraic
70
- notation input system,\n complete chess rules, a beautiful interface and a functional
71
- AI. It provides three game modes: \n Human vs. Human, Human vs. Ai, and AI vs.
70
+ notation input system,\n complete chess rules, a beautiful interface, and a functional
71
+ AI. It provides three game modes: \n Human vs. Human, Human vs. AI, and AI vs.
72
72
  AI.\n"
73
73
  email: lucas.sorribes@gmail.com
74
74
  executables:
@@ -77,6 +77,7 @@ extensions: []
77
77
  extra_rdoc_files:
78
78
  - README.md
79
79
  files:
80
+ - CHANGELOG.md
80
81
  - Gemfile
81
82
  - Gemfile.lock
82
83
  - LICENSE