게시판 인덱스

 
 FAQFAQ   검색검색   멤버리스트멤버리스트   사용자 그룹사용자 그룹   사용자 등록하기사용자 등록하기 
 개인 정보개인 정보   비공개 메시지를 확인하려면 로그인하십시오비공개 메시지를 확인하려면 로그인하십시오   로그인로그인 

오늘자 (11/23) 실습 뼈대코드

 
이 게시판은 잠겼으므로 글을 올리거나, 답변을 하거나 수정을 할 수 없습니다   이 주제는 잠겼으므로 답변을 하거나 수정을 할 수 없습니다     게시판 인덱스 -> 4190.210 Principles of Programming (Fall 2009)
이전 주제 보기 :: 다음 주제 보기  
글쓴이 메시지
이우석



가입: 2007년 9월 26일
올린 글: 72

올리기올려짐: 2009년11월23일 16:00    주제: 오늘자 (11/23) 실습 뼈대코드 인용과 함께 답변

* module You 내부를 구현해주시면 됩니다.

* 현재 10000번 게임을 하게 되어있고, 승률이 0.5가 넘어야 합니다.

코드:

module type PLAYER =
sig
  type selection = int   (* 0 : ROCK    1 : PAPER    2 : SCISSOR *)
  type submission = selection * selection
  val submit : unit -> selection * selection
  val select : submission -> selection
end

module Com : PLAYER =
struct
   type selection = int
   type submission = selection * selection
   
   let mine = ref (0,0)

   let submit () =
      let a = Random.int(3) in
      let b = Random.int(3) in
      let _ = mine := (a,b) in
      (a,b)
      
   let select os =
      let choice = Random.int(2) in
      if (choice = 0) then (fst !mine) else (snd !mine)
end

module You : PLAYER =
struct
   type selection = int
   type submission = selection * selection   

   ...

end

module Simul =
struct
   let round = ref 0
   let comwin = ref 0
   let youwin = ref 0

   let init () = round := 0; comwin := 0; youwin := 0

   let game playtime =
      while (!round < playtime) do
         let comopt = Com.submit () in
         let youopt = You.submit () in
         let com = Com.select youopt in
         let you = You.select comopt in
         let _ = incr round in

         match (com, you) with
         | (0, 1) -> incr youwin; print_endline "You win!";
         | (0, 2) -> incr comwin; print_endline "Com win!";
         | (1, 0) -> incr comwin; print_endline "Com win!";
         | (1, 2) -> incr youwin; print_endline "You win!";
         | (2, 0) -> incr youwin; print_endline "You win!";
         | (2, 1) -> incr comwin; print_endline "Com win!";
         | _ -> print_endline "Draw!";

      done;
      (!comwin, !youwin)
end


let init () =
   let _ = Random.init (Int32.to_int (Int32.of_float (Unix.time ()))) in
   Simul.init ()

let main () =
   let playtime = 10000 in
   let _ = init () in
   let (comwin,youwin) = Simul.game playtime in
   let winrate = (float_of_int youwin) /. (float_of_int playtime) in
   
      print_string ("Your Win Rate : " ^(string_of_float winrate)^"\n")

let _ = main ()
위로
사용자 정보 보기 비밀 메시지 보내기
이전 글 표시:   
이 게시판은 잠겼으므로 글을 올리거나, 답변을 하거나 수정을 할 수 없습니다   이 주제는 잠겼으므로 답변을 하거나 수정을 할 수 없습니다     게시판 인덱스 -> 4190.210 Principles of Programming (Fall 2009) 시간대: GMT + 9 시간(한국)
페이지 11

 
건너뛰기:  
새로운 주제를 올릴 수 없습니다
답글을 올릴 수 없습니다
주제를 수정할 수 없습니다
올린 글을 삭제할 수 없습니다
투표를 할 수 없습니다


Powered by phpBB 2.0.21-7 (Debian) © 2001, 2005 phpBB Group
Translated by kss & drssay