Tic-tac-toe: Difference between revisions

→‎{{header|Ruby}}: add introduction, listing the classes and describing the AI
m (→‎{{header|Haskell}}: fix English error (misspelling of “last resort”) in comment)
(→‎{{header|Ruby}}: add introduction, listing the classes and describing the AI)
Line 5,245:
 
=={{header|Ruby}}==
This implementation splits functionality into four classes: <code>Game</code>, <code>Player</code>, <code>HumanPlayer</code>, and <code>ComputerPlayer</code>. A game can be played between any combination of <code>HumanPlayer</code>s and <code>ComputerPlayer</code>s.
 
The AI for the computer uses certain heuristics to ensure that it never loses, but the AI is not as aggressive as it could be. The AI defends against the opening corner trap, but does not exploit it in its offense.
 
This implementation stores the board as a one-dimensional array and hardcodes all possible straight lines in <code>LINES</code>, rather than storing the board as a two-dimensional matrix and identifying straight lines dynamically.
 
<lang ruby>require 'set'
 
21

edits