From ruby-talk-admin@ruby-lang.org Fri Dec 16 02:53:42 2005 Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (8.12.3/8.12.3/Debian-6.6) with ESMTP id jBFHrgZk030233; Fri, 16 Dec 2005 02:53:42 +0900 Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 1EE6E59D2; Fri, 16 Dec 2005 02:53:47 +0900 (JST) Received: from localhost (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 33218F04847; Fri, 16 Dec 2005 02:53:47 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id D85E0F04846; Fri, 16 Dec 2005 02:53:45 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [210.163.138.100]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id E537563002C; Fri, 16 Dec 2005 02:53:45 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [127.0.0.1]) by beryllium.ruby-lang.org (Postfix) with ESMTP id AC16E33F11; Fri, 16 Dec 2005 02:53:25 +0900 (JST) Received: from localhost (beryllium.ruby-lang.org [127.0.0.1]) by beryllium.ruby-lang.org (Postfix) with ESMTP id D902633F09 for ; Fri, 16 Dec 2005 02:53:16 +0900 (JST) Received: from beryllium.ruby-lang.org ([127.0.0.1]) by localhost (beryllium.ruby-lang.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 15989-10 for ; Fri, 16 Dec 2005 02:53:16 +0900 (JST) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.201]) by beryllium.ruby-lang.org (Postfix) with ESMTP id 4B6EE33ECD for ; Fri, 16 Dec 2005 02:53:16 +0900 (JST) Received: by wproxy.gmail.com with SMTP id i6so710874wra for ; Thu, 15 Dec 2005 09:53:11 -0800 (PST) Received: by 10.65.116.16 with SMTP id t16mr1199009qbm; Thu, 15 Dec 2005 09:53:11 -0800 (PST) Received: by 10.64.148.10 with HTTP; Thu, 15 Dec 2005 09:53:11 -0800 (PST) Delivered-To: ruby-talk@ruby-lang.org Date: Fri, 16 Dec 2005 02:53:17 +0900 Posted: Thu, 15 Dec 2005 09:53:11 -0800 From: Adam Shelly Reply-To: ruby-talk@ruby-lang.org Subject: Re: [SUMMARY] Kalah (#58) To: ruby-talk@ruby-lang.org (ruby-talk ML) Message-Id: <491107790512150953t4962c717r916da826c8ed002@mail.gmail.com> In-Reply-To: <20051215133839.MWJU8318.centrmmtao04.cox.net@localhost.localdomain> References: <20051215133839.MWJU8318.centrmmtao04.cox.net@localhost.localdomain> X-ML-Name: ruby-talk X-Mail-Count: 85 X-MLServer: fml [fml 4.0.3 release (20011202/4.0.3)]; post only (only members can post) X-ML-Info: If you have a question, send e-mail with the body "help" (without quotes) to the address ruby-talk-ctl@ruby-lang.org; help= X-Original-To: ruby-talk@ruby-lang.org DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=oSStDe9rbxXprSxzzc4lg/HwjmPxmFDd78hX+RW9AUQrcKumvaWP/QRi2rydjkUf+GOLrT/HMq/ID4beL5c9HcO8TQhJY0HlCuMxRwxyHssuqL/5ZJ8M7CzP0jPTwjA65QyomaMITKnHwfOO8vF8eBf/lsYE9kydPRe8BFP6JW0= Content-Disposition: inline X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ruby-lang.org X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on beryllium.ruby-lang.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=7.0 tests=AWL,BAYES_00,BLARS00, BLARS_SPAM00,CONTENT_TYPE_PRESENT,MIMEQENC,QENCPTR1,QENCPTR2, RCVDFRMLOCALIP,RCVD_BY_IP,RCVD_IN_BLARS,RCVD_IN_BLARS_HOOPS, RCVD_IN_BLARS_SPAM autolearn=ham version=3.0.3 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Precedence: bulk Lines: 32 List-Id: ruby-talk.ruby-lang.org List-Software: fml [fml 4.0.3 release (20011202/4.0.3)] List-Post: List-Owner: List-Help: List-Unsubscribe: X-Virus-Scanned: by AMaViS snapshot-20020531 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by blade.nagaokaut.ac.jp id jBFHrgZk030233 There's nothing like a code review to make you see ways to improve your code... Based on James description of what #worst_case is doing I realized I could rewrite it in 2 lines: > def worst_case board > worst = 0 > opp_board = board.rotate 7 > 6.times {|i| > s = score_for(opp_board, i) > worst = s if worst < s > } > worst > end > end > > The code above is very similar to the last player we examined. The main new > element here is worst_case(), which is just a tool to find the opponent's best > move (worst for us). So this function should simply be: def worst_case board opp_board = board.rotate 7 score_for(opp_board,best_move(opp_board)) end Thanks for runing these always entertaining and educational quizes, James. -Adam