From ruby-talk-admin@ruby-lang.org Fri Dec 16 02:59:14 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 jBFHxEZk030359; Fri, 16 Dec 2005 02:59:14 +0900 Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 496235AC5; Fri, 16 Dec 2005 02:59:19 +0900 (JST) Received: from localhost (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 62D30F04842; Fri, 16 Dec 2005 02:59:19 +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 12F5AF04847; Fri, 16 Dec 2005 02:59:18 +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 23013630024; Fri, 16 Dec 2005 02:59:18 +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 8522D33F09; Fri, 16 Dec 2005 02:59:17 +0900 (JST) Received: from localhost (beryllium.ruby-lang.org [127.0.0.1]) by beryllium.ruby-lang.org (Postfix) with ESMTP id B38AC33F1E for ; Fri, 16 Dec 2005 02:59:09 +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 16890-01 for ; Fri, 16 Dec 2005 02:59:09 +0900 (JST) Received: from bidwell.textdrive.com (bidwell.textdrive.com [207.7.108.125]) by beryllium.ruby-lang.org (Postfix) with ESMTP id 63B0C33F09 for ; Fri, 16 Dec 2005 02:59:09 +0900 (JST) Received: from [192.168.1.100] (ip68-97-67-155.ok.ok.cox.net [68.97.67.155]) by bidwell.textdrive.com (Postfix) with ESMTP id 51394C1F99 for ; Thu, 15 Dec 2005 17:59:07 +0000 (UTC) Delivered-To: ruby-talk@ruby-lang.org Date: Fri, 16 Dec 2005 02:59:10 +0900 Posted: Thu, 15 Dec 2005 11:59:00 -0600 From: James Edward Gray II Reply-To: ruby-talk@ruby-lang.org Subject: Re: [SUMMARY] Kalah (#58) To: ruby-talk@ruby-lang.org (ruby-talk ML) Message-Id: <186FB96C-801E-4B6B-A368-B542FC91BD00@grayproductions.net> In-Reply-To: <491107790512150953t4962c717r916da826c8ed002@mail.gmail.com> References: <20051215133839.MWJU8318.centrmmtao04.cox.net@localhost.localdomain> <491107790512150953t4962c717r916da826c8ed002@mail.gmail.com> X-ML-Name: ruby-talk X-Mail-Count: 87 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-Mailer: Apple Mail (2.746.2) X-Original-To: ruby-talk@ruby-lang.org 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=-5.9 required=7.0 tests=AWL,BAYES_00, CONTENT_TYPE_PRESENT,RCVDFRMLOCALIP,X_MAILER_PRESENT autolearn=no version=3.0.3 Mime-Version: 1.0 (Apple Message framework v746.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk Lines: 39 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 On Dec 15, 2005, at 11:53 AM, Adam Shelly wrote: > 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 Hey, I like that. > Thanks for runing these always entertaining and educational quizes, > James. Thanks for giving me something to talk about, Adam. ;) James Edward Gray II