Skip to content

Instantly share code, notes, and snippets.

View thefonso's full-sized avatar

thefonso thefonso

View GitHub Profile
@thefonso
thefonso / minimax_spec.rb
Created December 5, 2012 15:26
How to test a no class module...the spec
require 'board'
require 'minimax'
class Test_Minimax_Ai
include Algorithm::Minimax
end
describe 'Test_Minimax_Ai' do
before (:each) do
@thefonso
thefonso / minimax.rb
Created December 5, 2012 15:28
How to test a no class module...the module
require_relative 'library'
module Algorithm
module Minimax # I return the best_move (win or block)
include Library # TODO namespace these methods
# max_move-find winningest Computer move, score it, add it to answer hash
# min_move-find winningest Human move, score it, add it to answer hash
def ai_moves(board)
turn_number = board.grid.select{ |k, v| v != " " }.keys.length
# receive board...is the game over? check for conditions...
@thefonso
thefonso / thekey.rb
Created December 5, 2012 15:37
How to test a no class module...the key
require 'minimax'
class Test_Minimax_Ai
include Algorithm::Minimax
end
@thefonso
thefonso / line13.rb
Created December 5, 2012 15:41
How to test a no class module.....line13
require 'board'
require 'minimax'
class Test_Minimax_Ai
include Algorithm::Minimax
end
describe 'Test_Minimax_Ai' do
before (:each) do
@thefonso
thefonso / generate_boards.rb
Created December 13, 2012 10:49
The little machine that generates X! boards.
def generate_boards(board, player)
virtual_board = board.dup
new_board_hash = {}
empty_spaces = virtual_board.grid.select{ |k, v| v == " " }.keys
empty_spaces.each do |space|
cloned_board = Board.new
cloned_board.grid = board.grid.clone
@thefonso
thefonso / move_as_someone.rb
Created December 13, 2012 11:35
place a move on the board and iterate the @i instance variable.
def move_as_somebody(board, player, empty_space)
board.grid[empty_space] = player
@i+=1
return board
end
@thefonso
thefonso / tmux_pairing.txt
Last active October 14, 2015 01:28
tmux pairing via ssh tunnel
both thefonso and kosh can log into name_of_some-machine.com
Note: if you don't have a github account take a look at this to generate your keys...
https://help.github.com/articles/generating-ssh-keys
tmux pairing via ssh tunnel
Step 0: both users edit ~/.ssh/config
thefonso:
#!/usr/bin/ruby
=begin
Usage: rtftomarkdown.rb FILENAME.rtf
Uses textutil, available on Mac only (installed by default)
Outputs to STDOUT
Notes:
Links are replaced with Markdown references (duplicate links combined).

Solving an algorithm for a friend to be able to tell his emacs what window he wants to replace his current window when he closes it.

class Rectangle
attr_accessor :height, :width
def area
@height * @width
end
end
class Square < Rectangle
def height=(height)