This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
#!/usr/bin/env ruby | |
# Input: Selected Text or Nothing | |
# Output: Replace Selected Text | |
require 'tempfile' | |
def unindent(text) | |
lines = text.split(/\n/) | |
level = lines.map{|l| l[/^\s*/].size}.min |
// suggested shell cmd line to run this: | |
// | |
// mongo --shell example2.js | |
// | |
// Note: the { out : … } parameter is for mongodb 1.8+ | |
db.things.insert( { _id : 1, tags : ['dog', 'cat'] } ); | |
db.things.insert( { _id : 2, tags : ['cat'] } ); | |
db.things.insert( { _id : 3, tags : ['mouse', 'cat', 'dog'] } ); | |
db.things.insert( { _id : 4, tags : [] } ); |
ruby code: | |
spec code: | |
All test are green now. this is leading me to create a new mechanism for game state in my app. | |
[ | |
the new game_state will have | |
if returned value == 1 => win | |
elsif returned value == -1 => loose | |
else => draw |
<!-- Add the following lines to theme's html code right before </head> --> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script> | |
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script> | |
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script> | |
<!-- | |
Usage: just add <div class="gist">[gist URL]</div> | |
Example: <div class="gist">https://gist.github.com/1395926</div> | |
--> |
def attempt_win(board) | |
ai_winmoves = { | |
:wm01 => {:a1=>"O", :a2=>" ", :a3=>" ", :b1=>" ", :b2=>"O", :b3=>" ", :c1=>" ", :c2=>" ", :c3=>" "}, | |
:wm02 => {:a1=>" ", :a2=>"O", :a3=>" ", :b1=>" ", :b2=>"O", :b3=>" ", :c1=>" ", :c2=>" ", :c3=>" "}, | |
:wm03 => {:a1=>" ", :a2=>" ", :a3=>"O", :b1=>" ", :b2=>"O", :b3=>" ", :c1=>" ", :c2=>" ", :c3=>" "}, | |
:wm04 => {:a1=>" ", :a2=>" ", :a3=>" ", :b1=>"O", :b2=>"O", :b3=>" ", :c1=>" ", :c2=>" ", :c3=>" "}, | |
:wm05 => {:a1=>" ", :a2=>" ", :a3=>" ", :b1=>" ", :b2=>"O", :b3=>"O", :c1=>" ", :c2=>" ", :c3=>" "}, | |
:wm06 => {:a1=>" ", :a2=>" ", :a3=>" ", :b1=>" ", :b2=>"O", :b3=>" ", :c1=>"O", :c2=>" ", :c3=>" "}, | |
:wm07 => {:a1=>" ", :a2=>" ", :a3=>" ", :b1=>" ", :b2=>"O", :b3=>" ", :c1=>" ", :c2=>"O", :c3=>" "}, | |
:wm08 => {:a1=>" ", :a2=>" ", :a3=>" ", :b1=>" ", :b2=>"O", :b3=>" ", :c1=>" ", :c2=>" ", :c3=>"O"}, |
.gist-highlight { | |
border-left: 3ex solid #eee; | |
position: relative; | |
} | |
.gist-highlight pre { | |
counter-reset: linenumbers; | |
} | |
.gist-highlight pre div:before { |
$(document).ready(function() { | |
var prefix = "https://gist.github.com/"; | |
$('a[href^="' + prefix + '"]').each(function(i) { | |
var $anchor = $(this), | |
$el = $("<p></p>"); | |
$anchor.replaceWith($el); | |
writeCapture.html($el, '<script src="'+$anchor.text()+'.js"></scr' + 'ipt>'); | |
$anchor.remove(); | |
}); | |
}); |
class Computer | |
include Algorithm::Regular | |
def move(board) | |
@player_symbol = 'O' | |
puts "computer move..." | |
ai_moves(board) | |
end |
class Computer | |
def move(board) | |
@player_symbol = 'O' | |
puts "computer move..." | |
taken_moves = board.grid.select{ |k, v| v != " " }.keys.length | |
if taken_moves == 1 | |
@move = ai_first_move(board) | |
elsif board.grid[:b2] != " " and taken_moves == 3 |