Search Results

Search found 17 results on 1 pages for 'dernalia'.

Page 1/1 | 1 

  • Ruby: implementing alpha-beta pruning for tic-tac-toe

    - by DerNalia
    So, alpha-beta pruning seems to be the most efficient algorithm out there aside from hard coding (for tic tac toe). However, I'm having problems converting the algorithm from the C++ example given in the link: http://www.webkinesia.com/games/gametree.php #based off http://www.webkinesia.com/games/gametree.php # (converted from C++ code from the alpha - beta pruning section) # returns 0 if draw LOSS = -1 DRAW = 0 WIN = 1 @next_move = 0 def calculate_ai_next_move score = self.get_best_move(COMPUTER, WIN, LOSS) return @next_move end def get_best_move(player, alpha, beta) best_score = nil score = nil if not self.has_available_moves? return false elsif self.has_this_player_won?(player) return WIN elsif self.has_this_player_won?(1 - player) return LOSS else best_score = alpha NUM_SQUARES.times do |square| if best_score >= beta break end if self.state[square].nil? self.make_move_with_index(square, player) # set to negative of opponent's best move; we only need the returned score; # the returned move is irrelevant. score = -get_best_move(1-player, -beta, -alpha) if (score > bestScore) @next_move = square best_score = score end undo_move(square) end end end return best_score end the problem is that this is returning nil. some support methods that are used above: WAYS_TO_WIN = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8],[0, 4, 8], [2, 4, 6]] def has_this_player_won?(player) result = false WAYS_TO_WIN.each {|solution| result = self.state[solution[0]] if contains_win?(solution) } return (result == player) end def contains_win?(ttt_win_state) ttt_win_state.each do |pos| return false if self.state[pos] != self.state[ttt_win_state[0]] or self.state[pos].nil? end return true end def make_move(x, y, player) self.set_square(x,y, player) end

    Read the article

  • Need help trouble shooting Https webserver error - SSL Handshake failed

    - by DerNalia
    I followed this guide: http://hints.macworld.com/article.php?story=20041129143420344 Here is my virtual host definition <VirtualHost *:443> SSLEngine on SSLProxyEngine On RequestHeader set Front-End-Https "On" CacheDisable * SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL DocumentRoot "/Users/me/projects/myproject/public" ServerName ssl.mydomain.com ServerAlias *.ssl.mydomain.com SSLCertificateKeyFile "/private/etc/apache2/certs/webserver.nopass.key" SSLCertificateFile "/private/etc/apache2/certs/newcert.pem" SSLCACertificateFile "/private/etc/apache2/certs/demoCA/cacert.pem" SSLCARevocationPath "/private/etc/apache2/certs/demoCA/crl" ErrorLog "/Users/me/Desktop/ssl.log" ProxyPass / https://localhost:3002/ ProxyPassReverse / https://localhost:3002 ProxyPreserveHost on </VirtualHost> And when I try connecting to the sevre viov the web browser, I get this error: [Thu Feb 02 16:50:40 2012] [error] (502)Unknown error: 502: proxy: pass request body failed to 127.0.0.1:3002 (localhost) [Thu Feb 02 16:50:40 2012] [error] [client 96.11.81.39] proxy: Error during SSL Handshake with remote server returned by /session/new [Thu Feb 02 16:50:40 2012] [error] proxy: pass request body failed to 127.0.0.1:3002 (localhost) from 96.11.81.39 () how do I debug / fix this?

    Read the article

  • Embed Google Calendar agenda to look like the version when editing or adding events [migrated]

    - by DerNalia
    How do I get the Google Calendar embed to look like it does when I'm actually inputting events into it? In the attached picture are two version of the Google Calendar agenda. On the left is the one you see when you are managing your calendar: adding events, etc. This is the preferred view. On the right is what happens when you try to embed the agenda on any webpage. Is there a way to get the embed to look like the cleaner version? (The left one?)

    Read the article

  • Ruby on Rails: link_to_remote and rel

    - by DerNalia
    I want a link to remote to have a rel tag, because I want to use facebox with it. I had it working with a regular link to... but I needed the link to remote to handle the event that a user doesn't have javascript enabled. this, currently does't work (except for the non-javascript part ) <%= link_to_remote "Ask a Question", {:url => {:action => :ask_question, :id => @container.id.to_s, :javascript_disabled => false }, :rel => 'facebox'}, :href => url_for( :controller => :view, :action => :ask_question, :id => @container.id.to_s, :javascript_disabled => true) %>

    Read the article

  • How to show / hide multiple elements at the same time with javascript

    - by DerNalia
    So, I have this between my head tags <script type="text/javascript"> hidden_links = document.getElementsByName("javascript_needed"); for (i = 0; i < hidden_links.length; i++) { hidden_links[i].style.display = "visible"; } </script> And my divs are all similar to <div name="javascript_needed" style="display: none;">stuff</div> the overall goal here, is to have these divs hide when javascript is disabled, and re-enable them when javascript is enabled.... but for whatever reason, my code doesn't work. I ever tried it in the webkit console, and nothing errored =\

    Read the article

  • Ruby on Rails: Javascript: How to grob focus when the text box appears

    - by DerNalia
    So, I have <script type="text/javascript"> function grabFocus(){ document.getElementByID("category_name").focus(); } </script> <div> <h1>New category</h1> <br/> <% remote_form_for :category, @category, :url=>{:action=>'ajax_create'} do |f| %> <%= f.error_messages %> <%= f.hidden_field :object_type %> <p> <%= f.text_field :name, :label=>false %> <%= f.submit 'Create' %> </p> <% end %> <br/> </div> and before I just had the <script type="text/javascript"> document.getElementByID("category_name").focus(); </script> at the bottom of the file. but other websites suggested that I make it a function, and call it in onLoad... but the partial I'm working with (entire thing pasted above) doesn't have a body... I'm showing the partial in the iframe that facebox uses... ideas?

    Read the article

  • complex URL remapping with friendly_id

    - by DerNalia
    I have the URL http://acme.example.com/view/view_container_content/15?javascript_disabled=true&container=aoeu but I want it to look like http://acme.example.com/view/container_name/content_name/ with friendly_id, I've seen how to do URL mapping with one object... but I haven't seen an example with two... ideas?

    Read the article

  • Ruby on Rails: How do you do HTTP auth over multiple controllers?

    - by DerNalia
    So, Here are the relevant routes map.namespace "admin" do |admin| admin.root :controller => :site_prefs, :action => :index admin.resources :site_prefs admin.resources :link_pages admin.resources :menu_bars admin.resources :services admin.resources :users end And I have this for one controller: before_filter :authenticate protected def authenticate authenticate_or_request_with_http_basic do |username, password| username == "1234" && password == "1234" end end How do I set up my admin controllers to authenticate no matter what page within any of those controllers is navigated to, yet only have it authenticate once among all the admin controllers, and have the code all in one spot. Right now, the only I can think of to authenticate is to copy the auth code into each controller, and I hate having duplicate code... so.... yeah

    Read the article

  • Rendering a different controller and action while keeping errors

    - by DerNalia
    I have a form in one controller(A) that renders a partial from another controller(B), and stays on A's edit page during editing / updating etc. However... When the partial form form controller B has an error, the error doesn't show up on A's edit page right now, if there is an error, I am doing (in controller B's update method) redirect_to :controller => "A", :action => "edit" and then this is built in... but I don't know what to do with it... the error needs to be sent to controller A... but.. it doesn't format.xml { render :xml => @varFromB.errors, :status => :unprocessable_entity } thanks

    Read the article

  • My fade in goes to all opaque for it goes to transparent

    - by DerNalia
    So, I'm trying to fade in a transparent div, kinda like hulu does when you click dim lights... here is what i have: //show the bg new Effect.Appear('darkBackgroundLayer', {duration: 0.3}); then when my pop up is initialized // create the div for background dimming if($('darkBackgroundLayer')){ Element.remove('darkBackgroundLayer') } var transparentBG = document.createElement('div'); transparentBG.className = 'darkenBackground'; transparentBG.id = "darkBackgroundLayer" transparentBG.style.display = "none"; document.body.appendChild(transparentBG); and the CSS for the new div .darkenBackground { background-color: rgb(0, 0, 0); opacity: 0.7; /* Safari, Opera */ -moz-opacity:0.70; /* FireFox */ filter: alpha(opacity=70); /* IE */ z-index: 20; height: 100%; width: 100%; background-repeat:repeat; position:fixed; top: 0px; left: 0px; } but, currently, it fades in... all the way to a solid back, then jumps to the .7 opacity... ideas?

    Read the article

  • Ruby on Rails: how to sort data in an array of active record objects right before iterating?

    - by DerNalia
    What is the best way to sort an array of active record objects by by a field? This array is a field of an object, link_pages, and I want it sorted by the field "sequence" <% @menu_bar.link_pages.each do |lp| %> <li id="page_<%= lp.id%>" class="ui-state-default"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <font size=5><%= lp.name %></font> | <%= link_to "remove", :controller => "admin/menu_bars", :action => :remove_page_from_menu, :page => lp.id, :id => @menu_bar.id %> </li> <% end %> maybe there is a way to do @menu_bar.link_pages.sort_by_sequence.each do .... that would be slick... but I just don't know.

    Read the article

  • Ruby on Rails: instance & class variables not maintaining value in controller

    - by DerNalia
    at the top of my controller, outside of any method, I have @@javascript_is_disabled = false and I have methods that that the view calls and invokes something like this @@javascript_is_disabled = params[:javascript_disabled] but when I need the @@javascript_is_disabled in completely different method.. it is always false. I know it changes in the method with params args... cause those methods behave differently, and appropriately And ideas?

    Read the article

1