--난수 발생 초기화
math.randomseed(os.time())
--플레이어와 컴퓨터의 점수
user_score = 0
comp_score = 0
--lookup 테이블, 관계에 대한 판단을 쉽게 하기 위해
lookup={}
lookup["scissors"] = {rock = "짐", paper="이김", scissors="비김"}
lookup["rock"] = {rock = "비김", paper="짐", scissors="이김"}
lookup["paper"] = {rock = "이김", paper="비김", scissors="짐"}
function GetAIMove()
-- 정수를, 관계 문자열로 변환할 수 있게 테이블 생성
local int_to_name = {"scissors", "rock", "paper"}
return int_to_name[math.random(3)]
end
function Evaluate(user_guess, comp_guess)
print("당신 : "..user_guess.."\n컴퓨터:"..comp_guess)
if(lookup[user_guess][comp_guess]=="이김") then
print("당신이 이겼습니다")
user_score = user_score+1
elseif(lookup[user_guess][comp_guess] =="짐")then
print("컴퓨터가 이겼습니다")
comp_score = comp_score +1
else
print("비겼습니다")
end
end
loop = true
print("s = 가위 / r = 바위 / p = 보\nq=종료")
while loop == true do
print("점수")
print("당신 : "..user_score.."컴퓨터:"..comp_score)
user_guess = io.stdin.read '*1';
local letter_to_string = {s = "scissors", r = "rock", p = "paper"}
if (user_guess =="q") then
loop = false
elseif(user_guess =="r") or (user_guess =="s") or (user_guess =="p") then
comp_guess = GetAIMove()
Evaluate(letter_to_string[user_guess], comp_guess)
else
print("잘못된 입력입니다")
end
end
print("루아 스크립트 예제 종료")
이대로 실행하면 user_guess = io.stdin.read '*1'; 이쪽 구분에서 에러가 발생하는데
had argument #1 to 'read' <FILE* expected, got string>
라고 에러가 발생하는데 도통 무슨 문제라고 하는건지 알 수가 없네요
혼자 공부하는 중이라 물어봅니다.
user_guess = io.read(1);
하시면 될듯하군요.
혼자 공부하신다면 레퍼런스는 필수입니다.
target=_blank>http://www.inf.puc-rio.br/~roberto/book/
참조하세요~