This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn minimax-score [player opponent board depth] | |
| (or (value board player opponent depth) | |
| (let [values (map #(minimax-score opponent player | |
| (place-move % (:piece opponent) board) (inc depth)) | |
| (available-spaces board))] | |
| (best-score opponent values)))) | |
| (defn minimax-move [maxplayer minplayer board] | |
| (let [values (map #(minimax-score maxplayer minplayer | |
| (place-move % (:piece maxplayer) board) 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_minimax_move(board,max_symbol,min_symbol) | |
| set_min_and_max_players(max_symbol, min_symbol) | |
| best_score_for_max = @max.starting_score | |
| alpha = -100 | |
| beta = 100 | |
| depth = 0 | |
| board.available_spaces.each do |space| | |
| test_board = copy(board) | |
| test_board.place_move(@max.symbol, space) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'sinatra' | |
| require 'warden' | |
| class YourApp < Sinatra::Application | |
| get "/" do | |
| erb 'index'.to_sym | |
| end | |
| get "/protected_pages" do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| get "/login" do | |
| erb '/login'.to_sym | |
| end | |
| post "/session" do | |
| warden_handler.authenticate! | |
| if warden_handler.authenticated? | |
| redirect "/users/#{warden_handler.user.id}" | |
| else | |
| redirect "/" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'sinatra' | |
| require 'warden' | |
| class YourApp < Sinatra::Application | |
| use Rack::Session::Cookie | |
| use Warden::Manager do |manager| | |
| manager.default_strategies :password | |
| manager.failure_app = YourApp | |
| manager.serialize_into_session {|user| user.id} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Warden::Strategies.add(:password) do | |
| def valid? | |
| params["email"] || params["password"] | |
| end | |
| def authenticate! | |
| user = Datastore.for(:user).find_by_email(params["email"]) | |
| if user && user.authenticate(params["password"]) | |
| success!(user) | |
| else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use Warden::Manager do |manager| | |
| manager.default_strategies :password | |
| manager.failure_app = YourApp | |
| manager.serialize_into_session {|user| user.id} | |
| manager.serialize_from_session {|id| Datastore.for(:user).find_by_id(id)} | |
| end | |
| Warden::Manager.before_failure do |env,opts| | |
| env['REQUEST_METHOD'] = 'POST' | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'sinatra' | |
| require 'warden' | |
| class YourApp < Sinatra::Application | |
| use Rack::Session::Cookie | |
| get "/" do | |
| erb 'index'.to_sym | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| datastore = {:users => {1 => {:name => "Mike", :email =>"[email protected]"}, | |
| 2 => {:name => "John", :email => "[email protected]"}}, | |
| :tasks => {1 => {:description => "First task"}, | |
| 2 => {:description => "Second task"}}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe "Foundry" do | |
| def app | |
| @app ||= Foundry | |
| end | |
| #...some other tests... | |
| it "should send the form values to a new User Interactor and create a user" do | |
| params = {"name" => "Test", "email" => "[email protected]"} |