Skip to content

Instantly share code, notes, and snippets.

@salma71
salma71 / AI_body_structure
Last active March 3, 2018 23:55
ttt-AI-logic-blog-post
module Players
class Computer < Player
def move(board)
computer_move(board)
end
def computer_move(board)
end
def move(board)
#center position
if !board.taken?("5")
"5"
else
computer_move(board)
end
end
def computer_move(board)
win_move(board) || block(board) || corner(board) || middle_corner(board)
end
@salma71
salma71 / README.md
Created March 9, 2018 03:28 — forked from hofmannsven/README.md
My simply Git Cheatsheet
def self.scrape_level_two
name = URI.encode(gets.strip)
agent = Mechanize.new
page = agent.get("http://www.packopumps.com/en/products/different-kind-of-pumps/#{name}")
#get each pump series_list
page.search("div.categoryBlock").collect do |ele|
all_series = self.new
all_series.name = ele.text
all_series
end
def list_product
PumpSelection::Scraper.scarp
PumpSelection::Scraper.scrape_product
PumpSelection::Scraper.display_product
end
def list_series(input)
PumpSelection::Scraper.scarp
PumpSelection::Scraper.scrape_product
PumpSelection::Scraper.display_series(input)
end
def self.display_series(input)
index = input.to_i - 1
puts "#{@@all[index].series}"
end
def self.display_product
@@all.each.with_index(1) do |product, i|
puts " #{i}. #{product.name}"
end
end
def self.scrape
@doc = Nokogiri::HTML(open("http://www.packopumps.com/en/products/different-kind-of-pumps"))
@scraping_block = @doc.css("div.listingByBlockContainer div.categoryBlock")
end
def self.scrape_product
@scraping_block.each do |ele|
name = ele.css("a.desc").text.strip
series = ele.css("div.sub ul li").text.strip
product = self.new(name, series)
@@all << product
end
end