Skip to content

Instantly share code, notes, and snippets.

@esehara
Last active August 29, 2015 14:06
Show Gist options
  • Save esehara/23987eeef02816678e4b to your computer and use it in GitHub Desktop.
Save esehara/23987eeef02816678e4b to your computer and use it in GitHub Desktop.
ruby-prolog.sample.rb
# -*- coding: utf-8 -*-
require 'ruby-prolog'
c = RubyProlog::Core.new
c.instance_eval do
janken['グー', 'チョキ'].fact
janken['パー', 'グー'].fact
janken['チョキ', 'パー'].fact
win_p1[:P1, :P2] << [janken[:P1, :P2]]
win_p2[:P1, :P2] << [janken[:P2, :P1]]
def win?(p1, p2)
if query(win_p1[p1, p2]).length != 0
'Win Player 1'
elsif query(win_p2[p1, p2]).length != 0
'Win Player 2'
else
'Draw !!'
end
end
puts query(janken[:P, 'チョキ']).to_s
puts win?('チョキ', 'パー')
puts win?('グー', 'パー')
puts win?('パー', 'パー')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment