In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

やっつけ向聴計算機

@author uwi
現在の手牌からの6向聴以内の各和了形のツモ限定の確率上位5位を求める。
役の総当たりを枝刈りしている。余力あれば翻数もつける?
残り牌数も指定できるがI/Fめんどくさい。
鳴きとかカンもめんどくさい。

画像は http://www4.cty-net.ne.jp/~l6000all/
画像の貼り方は http://wonderfl.kayac.com/code/7759319c71a3b018008d108bfd08425cd72a5c77
Thanks!

2009/07/13 細かい修正
Get Adobe Flash player
by uwi 12 Jul 2009
package {
    import flash.display.*;
    import flash.text.*;
    import flash.utils.*;
    import flash.events.*;
    
    /**
     * @author uwi
     * 現在の手牌からの6向聴以内の各和了形のツモ限定の確率上位5位を求める。
     * 役の総当たりを枝刈りしている。余力あれば翻数もつける?
     * 残り牌数も指定できるがI/Fめんどくさい。
     * 鳴きとかカンもめんどくさい。
     *
     *
     * 画像は http://www4.cty-net.ne.jp/~l6000all/
     * 画像の貼り方は http://wonderfl.kayac.com/code/7759319c71a3b018008d108bfd08425cd72a5c77
     * Thanks!
     *
     * 2009/07/13 細かい修正
     */
    public class ShantenTest extends Sprite {
        private const haku : String = "R0lGODlhGAAiALMAAAD//4RCAISEhMaEAP/33v///6YAAABZANsAAAAAAAAzZs/Pz////////////9zc3CH+LWh0dHA6Ly93d3cuYmwubW10ci5vci5qcC9+bDYwMDBhbGwvDQqC3ILCg1qDkwAh+QQBAAAAACwAAAAAGAAiAAAEWhCMSau1IcjLey5gKI5k8QhlWp5qCz6sCc90baOyrd/v7s+4nzAo9BGLuiOyplwCe05aMzp1VpdXZLa4HUKjsO5PbPyCyTt00kxlW91YuFbOpXtz4BMADwZEAAA7";
        private const hatu : String = "R0lGODlhGAAiALMAAAAAAABZAAD//4RCAISEhKUAAMaEAM7Ozt4AANzc3P/33v///////////////////yH5BAEAAAIALAAAAAAYACIAAAS3UJhJq7VjyMt7XmAojuSSEGVanmoLJqwJz3Rto7Kt3+/uz7ifMPg7GA+83O4QCCBrRNuRGdBFacYmVQm7wrLNpukJ7CWm4UWVSe6a2QF1QiuGmtXOOV7MjYLCWXhGdkp/YXGCbVdgVU5gg245YHtUgE9EgWIEfIeXPWxzjnNHljEwcXSHh3iRX0irfDAipqFVcqGUZER/VFuGea2yeMMmIJs5VyvCZl5ChM4+zdDB01ACXNUJAhEAADs=";
        private const man1 : String = "R0lGODlhGAAiALMAAAAAAAAxYwD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////yH5BAEAAAIALAAAAAAYACIAAAS/UJhJq7VjyMt7TmAojmSCEGVanmoLIqwJz3Rto7Kt3+/uzzjf4UAoDmtBxPA4JACezyOwh4gSDs9AIsAFIHshqIqWhI1+sDJap15/c7blYdeGLQsF6Tt+KCASeHRUNHhDeXJkVHJ9fXiOezN5jn5mIYk5IHgmjYE8cCGTCAWDaaQwfqFspqKPlJ40d6ydrzN9sqiIUzJ3R5OOemWooYCjhbqVxX+/nJczoJrEkzltIAMjH1R1lpWkBAJwbjQCEQAAOw==";
        private const man2 : String = "R0lGODlhGAAiALMAAAAAAAAxYwD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////yH5BAEAAAIALAAAAAAYACIAAATIUJhJq7VjyMt7TmAojmSCEGVanmoLIqwJz3Rto3J9HES/2zEdD0AkAoM1YmAZAuJqq+PzuOsRfrTpbssjFInXw2yKAB+KAdDSOH4h1ERXOzc61sg2rtQtPBQKWHd8MzsFb397OTR/hVxic4RcgH+UhlmDk5QzIpd0CX8mfpo3gyGVCAWDMHgzhqdOqjCnlqSKW66jtTR+qJqAW50wtz+VlIFkuJqfqYyQb5+fh4yitEjPy6nYlDmsIAMjH3ys15tNWQKKdkcCEQAAOw==";
        private const man3 : String = "R0lGODlhGAAiALMAAAAAAAAxYwD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////yH5BAEAAAIALAAAAAAYACIAAATMUJhJq7VjyMt7TmAojmSCEGVanmoLIqwJz8hxELhNz6g82wSAULjjvXbCQEBUjO2YtkPTSQMGidNecbg8FrW00Q1H0Bll0ShuODRTEcIyt6sE0MCggNB1no1qUVleVTYFBW53gzCFCAmGgj40hoVpUn2LaYeGmwU7YDCam34hiT4ghiYHnE2fjaeiBYpvkgirrLK1sJCEqrmPt5G9q4eBl1HEvpxun52cnY6xk5enjo2bhb8wnyGbr5w+ra4DIx9e4a6mpHcCkVPuAhEAADs=";
        private const man4 : String = "R0lGODlhGAAiALMAAAAAAAAxYwD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////yH5BAEAAAIALAAAAAAYACIAAATRUJhJq7VjyMt7TmAojmSCEGVanmoLIqwJz3Rto7KNHAdB8LeXjUcAGAFAGg7GaxaNgYAxCVvCpsdEIDRVCkFGMAJ5GANqVkQCIGNPD2FvzkSuw9m5GG3tPkaFM2lqLUF5NU1lOoIzTQUFVHJDBwVqjjp6No48j4iRTIiPjqKUnjChojMipSCOJpOohXusqAWAgbYzlKOXi6a0vLaNCLuKwbq0nbcyjUCjolRpx6gJrZrKMKzUlZqvpFWAIaKzozmLIAMjH4C9IantSgKGl5cCEQAAOw==";
        private const man5 : String = "R0lGODlhGAAiALMAAAAAAAAxYwD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////yH5BAEAAAIALAAAAAAYACIAAATeUJhJq7VjyMt7TmAojmSCEGVanmoLIqwJz/QM1DAqz8dB/AdAYBjYxWpBgFI4oulwykTRWHvWlAhA8IDLvXjb5a17hPXEIC0X9+wlb2olcO01EaIJsVDcmz2ZJkJTIENKdE8hCFIvfYRFfl8zjAcFBT0ikFQIPQWKlWRWNZWcbn2ZYG6WlaudTpEIqquSiacwIJUmlLJsryGssK91XZ2/XaE0v628Rqmwu8s0lM6flm6uMql9rKumZbDTnwm4o7W34p6jusrevrji2zvHigkDIx+R8vM7mE4CmmRdBEQAADs=";
        private const man6 : String = "R0lGODlhGAAiALMAAAAAAAAxYwD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////yH5BAEAAAIALAAAAAAYACIAAATVUJhJq7VjyMt7TmAojmSCEGVanmoLIqwJz8hxEHad06hMw4CgjQDYwXo/GEgYFB5mSNrwAAgEEtYAgPeC2ahBFbQLBHS/z2QUEUII3QBceuzzgkNNY0x6Ny3fdD9VZFhWdWtsbV+JZHtJXwUFeoE/NgVskUlHjTORlmhzjjqQB5Gml1x1kqczIqmtCZEmpaaaiCGsBZyiNJestrsIuZq8kMK1wHWlx5mSi5SkT6emRmu+rLG6npQg2pietKibPriy2ac+iIkDIx9k6oywnAQCdcT3AhEAADs=";
        private const man7 : String = "R0lGODlhGAAiALMAAAAAAAAxYwD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////yH5BAEAAAIALAAAAAAYACIAAATMUJhJq7VjyMt7TmAojmSCEGVanmoLIqwJz0d9zDiOyvgBADZCLRcjIn4I32+oexEByV8gAM3tjECpyOrM/QAhYxFWEwICXeN19q3absQ1QvQjEJbqNAxEPaPzPDgrcXpkNQUFTFyBhgVziGJyOIiHb3AwcpaJiJyOTYGbnDNbM3IgiCYHnYCCp6IFhZIzjqusRKuehIE2tKK2ZL2QiTafhqpDnZyKcsGQCaiUpU6nz4+UqpDSPCGcrp08siADIx9dsnNdpKUCjGJiAhEAADs=";
        private const man8 : String = "R0lGODlhGAAiALMAAAAAAAAxYwD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////yH5BAEAAAIALAAAAAAYACIAAATPUJhJq7VjyMt7TmAojmSCEGVanmoLIqwJz8hh0ziMyjlw57MdEOQ7AHUvms2IABB+OKES4EtQizkpzEYNBahPJpLHBbxAXypUyg0kEejrT2t+w9CBbzAZOpLGRzVLR1pKNgUFUDSFWwcFcIiEdjOIh0uKWpeOjoidUXaJnY93fXs8IIgmnJFZdiGiCAWTMUCPsECMMLCjrTyCjrGeuHbAu5eLSUuJRqKda2+2sAmplaakso/TlavIp6ip2qI8jCADIx9vuaVw6zoCvoFHAhEAADs=";
        private const man9 : String = "R0lGODlhGAAiALMAAAAAAAAxYwD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////yH5BAEAAAIALAAAAAAYACIAAATdUJhJq7VjyMt7TmAojmSCEGVanmoLIqwJz0d9IPaso7KOAIAaIeiD8YqwIDB48x1ptWViiXzOgIkACKDFNY2vmQhgIicOxJmVBkCUrzV1mPaTBQnodAyKfk2XQDtzP2YwIAGIiD1WIjA2JHI9OjYFBXFFa44HBW6VSHtFlTWWNl+gXpSblatOg5arnIYhgj0glSaqnpiDIbAIBYNgkjOcvlXBML6xu5KUv6zHzcWspJfCmptxsKvWVtOsCbeikbLAnOGiubRitrfosIvBIAMjH3OZbnONOwLDn58CIgAAOw==";
        private const nan : String = "R0lGODlhGAAiALMAAAAAAAAxYwD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////yH5BAEAAAIALAAAAAAYACIAAAS7UJhJq7VjyMt7TmAojmSCEGVanmoLIqwJz3Rto7Kt3+/uzzjfYegL6oYAos5oOwCehx3T9gTkatPaExblXbXJ5LJXQ1YRXVp26AQETGIsefZMJNvjHBsBqkLTMFNVBG1+SoE9UX1VAY0Bf0A9dwhub3aLcTEwdk59bXBbkTJ2d4VsZ6KbpFt+lHWpm3Wklq5kTIt8b2hVV1MJjZ4ET7SwqiJ+c5o7II5fyssiXj/TWdNyztZAAtjZCAIRAAA7";
        private const pei : String = "R0lGODlhGAAiALsAANzc3P///wAAAM7OzsaEAISEhAAxYwD//4RCAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAcALAAAAAAYACIAAASz8JBJq7UIyct7DmAojmQAFGVanmoLAqwJz3Rto7Kt3+/uz7ifMLgbGH1Em1Fw1CVtgmiz9qSBokxnb2Y8YnO06kA6FmzDW680CugO0LLlm00mA7fYMmCNhcNABgJ7glgCBgZbTwFmdIYifjBjAItMUWd3YIKDfTtEc22WbJ09Y0uNbm4xbWVRgZSFnEGsiIiAhYcvQQGHtS+AvCEwuo9WI5BCo2DIVJfLmM5aytAnB9LQBxEAOw==";
        private const pin1 : String = "R0lGODlhGAAiALMAAAAxYwBZAAD//4RCAISEhKUAAMaEAM7Ozt4AANzc3P/33v///////////////////yH5BAEAAAIALAAAAAAYACIAAATgUJhJq7VjyMt7XmAojuSSEGVanmoLJqwJz3Rto7Kt3+/uz7ifMFg7GI9GHRF2BDifx9rS6CQgCc4ksEclJJ7PE0AbS1C75oP4rC4fANbxIUAPnLHt4HtPTyAQCXR7cmVwcIEJBUYFiFh4hXwHigWTc4MwQWNjAZWUknaamC+ac4yepqBvoiahAYmJk4ihhY6WipKWjgAKZQutdp59obxBCnCqgXUwY1i8ZQq+XVdyAAvORArGcWDMu85lMNBV09Xf4OEg3NXWUj000CPmWzlCSu71PPT4NEv7/AL6/CUQEAEAOw==";
        private const pin2 : String = "R0lGODlhGAAiALMAAAAxYwBZAAD//4RCAISEhKUAAMaEAM7Ozt4AANzc3P/33v///////////////////yH5BAEAAAIALAAAAAAYACIAAATFUJhJq7VjyMt7XmAojuSSEGVanmoLJqwJz3Rto7Kt3299/MDDDuc7AI7Hn444+x0TAChAWWPCjFFAITvl5WDTKcJoXPZmx0LhoH56a1l2OfqeKZLaMEBRhykWeFgLfFVnfoBIAINmX4cihH07kjGTlVZNQVSRCT8Bnp6aNJedAQmloEKFXweepgWnAamihqasB2OxpZueamyvuqo1p3KnjDQLoAGvrAGNlDMgycy0z9DIn83O1dYjQ9SVs9rgMAQC4uMCEQAAOw==";
        private const pin3 : String = "R0lGODlhGAAiALMAAAAxYwBZAAD//4RCAISEhKUAAMaEAM7Ozt4AANzc3P/33v///////////////////yH5BAEAAAIALAAAAAAYACIAAATDUJhJq7VjyMt7XmAojuSSEGVanmoLJqwJz3Rto7Kt329y/L8dz/QDGIPCGc53PB6SsCXgYJxOobFElWrEZgHaLkCBXS6aYzJ0qTgbF+p1rw1SAJG6Ze0X6ONrejN8AQd+T0N7hAiLhYeAPTQBBQUHkwE7gTALl5MFCQE5NJkJIJKVoKFKkDOlfauir5oid45ZSYOEjqN7hYSGUbE0jX2+h7s1xL2XwKk1m599nzLHrJu+qMxQrdjZ2iKwzV5RAuHiAhEAADs=";
        private const pin4 : String = "R0lGODlhGAAiALMAAAAxYwBZAAD//4RCAISEhKUAAMaEAM7Ozt4AANzc3P/33v///////////////////yH5BAEAAAIALAAAAAAYACIAAATJUJhJq7VjyMt7XmAojuSSEGVanmoLJqwJz3Rto7Kt3+/uz7jZYTikEYvA3jDARA4BUGQssQwcmsRo9AALXq9N6wEw1nKnCaZVDYOS3UnTIpBmphcKQAIOUHRfIGEBIAp5b31+aIFMPQoLbnhxMyM0joQ0QT8/mZo7nJ08OaA1n6OSMEdnqEeYSmVkZ1Vikk+HR4JIXodvS2BrZ5lurzBqvpJ5e1B7jnRsg38mhVqIi2A9mY6QiYuDOZyWkZMiraKm0OakAuXmAhEAADs=";
        private const pin5 : String = "R0lGODlhGAAiALMAAAAxYwBZAAD//4RCAISEhKUAAMaEAM7Ozt4AANzc3P/33v///////////////////yH5BAEAAAIALAAAAAAYACIAAATpUJhJq7VjyMt7XmAojuSSEGVanmoLJqwJz3Rto7Kt329y/L8aMDjD+Q6BJPEIaC6NyEA0+HM6DzCjNLnFHgBfKzaW4EYDsyZYXXyhuWWTApBgAxTZ10KZfCnma3d4ZCBcPQkKC2oLg2QJI0MHiSCNjjQ/ZmM8OTCYW1KaNEaXUgimSKFtnDABBQUHrmg6ozN7Ca4FcbOHMIWvBQG8qjaFfavDR0CQQ6IvVVcznqDDYdVeU0pjRoFrXp9deSZqYXSsfEnDdHZ4tnDB4Y9Wgo97nz1GiYuNxcE5o5OMaoxodmzHLAEFDdYQEAEAOw==";
        private const pin6 : String = "R0lGODlhGAAiALMAAAAxYwBZAAD//4RCAISEhKUAAMaEAM7Ozt4AANzc3P/33v///////////////////yH5BAEAAAIALAAAAAAYACIAAATvUJhJq7VjyMt7XmAojuSSEGVanmoLJqwJz3Rto3Jy7PvM9zQcbAco9ojGQ/CFPCSdACgwposWrU4odiZMXLVe43VpUgDCZ8AiXfQquC+F2QpQLOZQOVxmv94TfUV/ezN2IG8whoOENo2NXY6RMJCSjpA/SkM/NV07AZ9HB58BU1SepKCnoqSZpqQIsKKysAiyjAEFBQe5AQm4urxkCQu9uQW+xAnGyIQguLsBIc8F0TmUozXYnEyr3aqphLOxqAe0tpMvvrm71OrA7c3Fucjyx9HNxMDV+dDpVMPEPr1wJjDHP4AhZozgJMBgJRsCIgAAOw==";
        private const pin7 : String = "R0lGODlhGAAiALMAAAAxYwBZAAD//4RCAISEhKUAAMaEAM7Ozt4AANzc3P/33v///////////////////yH5BAEAAAIALAAAAAAYACIAAATxUJhJq7VjyMt7XmAojuSSEGVanmoLJqx5zDNs33g8A3yd/6jFodc7/HJBwJBI8wFBPGV0qTQ+F4DEdFu9YqVEZtMWVHwBZ6raGkyYQ1kumP26KRRhsBTWxpmjaVF8dX4icTxagyZHMHdhi30JTVaSOzwLCoowMwGdNZydd5maoAeepadkL6YHCK6sAa2vsaqLAQUFB7gBCbe5uzdtC7y4Bb3DCcXHtQkgt7oBIc8F0YsxN5282J1Iq6axp9/ilG2srgiwsui0mr24utTuv/HMyMrRxLjLms6/1cP+CPVx1ukFwWrBCI2wsTCYAGuMGAmIAAA7";
        private const pin8 : String = "R0lGODlhGAAiALMAAAAxYwBZAAD//4RCAISEhKUAAMaEAM7Ozt4AANzc3P/33v///////////////////yH5BAEAAAIALAAAAAAYACIAAATTUJhJq7VjyMt7XmAojuSSEGVanmoLJqwJz3Rto3Jy7PvM9zQcbAco9ojGQ/CFPCSdACgwposWrU4odiZMXLVe43VpUgDCZ8AiXfQquC+F2QpQLOZQOTyHro1rQk1PYlFKMIF0WIlZezBfY49tjWZ9amxpb4dxeEV2nHWZVDN/o5JkOlKDdFOIWlmLUY1oYJFnk5dea5WhQnKEnr+8L6W2xDdMqYXJrEywr2KGorWzpFSUkLqQwmWfwHR6mjJ2V3cJ40XlsuYhoXYgoYcCfDb0NAIRAAA7";
        private const pin9 : String = "R0lGODlhGAAiALMAAAAxYwBZAAD//4RCAISEhKUAAMaEAM7Ozt4AANzc3P/33v///////////////////yH5BAEAAAIALAAAAAAYACIAAAT+UJhJq7VjyMt7XmAojuSSEGVanmoLJqwJz3Rto+ah68nO+4cZTgco7oqAozEYOxifSagzGcRFn9No1lkFIbPQLxJmTYwB5qI5jQYoYguoQi5/D+PFEFKff8cSCiFvgSCDgkIvQD0+izuICzoBkjuSAZSTTEOTm5acB5gxlgijnwejCKWnpaEFBQetAa2vBbGusGQgAQmtBQm6vL67rb4mOAuxrwHHtsrItC93lSHSuZIvfyMJ2dm4OYyKit2RmJ/klTxNnuqdll3H5Z3wpeeWoZz0ley6ob6SwZX//CmDw+kYO4PloIE4YFBZNYcNr+HQJoJiCIvXTgiQYaOjDQECEQAAOw==";
        private const sha : String = "R0lGODlhGAAiALMAAAAAAAAxYwD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////yH5BAEAAAIALAAAAAAYACIAAASxUJhJq7VjyMt7TmAojmSCEGVanmoLIqwJz3Rto7Kt3+/uz7ifMCj0EYu6o+1wIDgJTJoSwXwCrtgojFg9YAGBwBegPWJJ4LAY2BNRmV4AadujeZlXOC8Hv4+hB1J1fl8gWYF0OQhXi2IAMF+IMTMJZwGVkFiCOYaQi5lXOVN5j2Rxl6J1CJWli6eqSoZ+caqTNWNneza4qLo0CWpqtYk1KTtTSGyKycrMvs5AAsvOAhEAADs=";
        private const sou1 : String = "R0lGODlhGAAiALMAAAAAAABZAAD//4RCAISEhKUAAMaEAM7Ozt4AANzc3P/33v///////////////////yH5BAEAAAIALAAAAAAYACIAAAT+UJhJq7VjyMt7XmAojuSSEGVanmoLJqwJz3Rto3JynARx7L+ejoabHXy839GHnBWdvqW0p4QVqz0AoEfQMqMxHlO70ALKW+auSBADEu84PNgOt4/mQ97cU1hfCj5kZmhnWjt/MnhwjHJxYFdZAHqHe2lrL2qEm1p+R2GBiI6NXAR+V0tdk5ZWfmEFBwWmlKtbS0QvCQW7CQsHvsB1Oj+vC7xHqciTeom9BSawBAHTAVk6byZF0LEH1QEL1D9kzc673gnf1GQyTzDT4Ojo4OBVYT/T3dLd+94BxGzUpiGgNjDgtGbTcCxAAEMBw14jwoiAsauALl43csFQ8gyERRsZ5IZVFLmLGK4cFwcYu2jsIxEBOVxohCEgAgA7";
        private const sou2 : String = "R0lGODlhGAAiALMAAABZAAD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////////yH5BAEAAAEALAAAAAAYACIAAASfMJRJq7VCyMt7RmAojiRyDGVanmoLHqwJz3Rto7Kt329t/EDDDmczAI5HoY5YQxydgFyNSQMBDlEpjVoDGHcwLuyH/A173esRLD5Yn9pZGxa9stEzMta8xI+TSWdxUEhxYX5gfXFGSF6CNlCRj01OWIiHhnt2kzRkSUo8hmtrnDNvWaU0dYltel6gU4iMs6lujVG1K4qJvAMBmbwwAREAADs=";
        private const sou3 : String = "R0lGODlhGAAiALMAAABZAAD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////////yH5BAEAAAEALAAAAAAYACIAAAS8MJRJq7VCyMt7RmAojiRyDGVanmoLHqwJz3Rto7Kt329t/EDDDmczAI5HoY5YQxydgFyNSQMBDlEpjVoDGHcwLuyH/A173esRLD5Yn9pZGxa9stEzMta8xI+TSWdxUEhxYS9BQiMHiUpESIE0RpCOL09PTZdRhyZOWH5WnzJMXnY6pVuIZUp5k16VJmtrNrKmRISguKM9dWC9cqp7rGNfr5xYpV4+gMoxyIWZkLudi1Ukx2DZJwGG2jMBEQAAOw==";
        private const sou4 : String = "R0lGODlhGAAiALMAAABZAAD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////////yH5BAEAAAEALAAAAAAYACIAAATDMJRJq7VCyMt7RmAojiRyDGVanmoLHqwJz3Rto7Kt3+9h/EADLAic4YaAZFLoUy6NPURSCpBRr1Cr9FDVAri9GA1g+NbI5uywvGT+lD81LMlN1+9ykDJK7crnW2eBcm9ccT5lhkxiTWhkSI6LRwd9UzCVVX87m4xscJCfMJNXlpRTpYx6YF6rmmg2rzSTb21rcJJhdHQzunajfXx7OZOAdsU1s4lkbsqHnUtPjWy4Vk6Zpk7DfCOXJJqcOgMBOeA6AREAADs=";
        private const sou5 : String = "R0lGODlhGAAiALMAAABZAAD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////////yH5BAEAAAEALAAAAAAYACIAAATbMJRJq7VCyMt7RmAojiRyDGVanmoLHqwJz3Rto7Kt36/h/7WfEIY7AI5HQxCZJL6OCGgtCqDKilHjiwYCaK9bgMG7E5OdpnFSSfMhfWijdy1Uy2dYpInA5x+oVWAyVV4IfIYEJoQ0RWNGSoYHiQeOYmxFSU0EBgSUmWJxTF6cfEqigjp+fjuYTH99ikyXT4RVkpFWUjF/c2mdm7xfcY+jpaXEjD1vkn2dapahc4EjR3dxgFszXVCoWmc2i3jKj2wzbuTRauUw6k27p1PwuyRT9Ls7+HgBOfk7AREAADs=";
        private const sou6 : String = "R0lGODlhGAAiALMAAABZAAD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////////yH5BAEAAAEALAAAAAAYACIAAATIMJRJq7VCyMt7RmAojiRyDGVanmoLHqwJz3Rto7Kt36/h/8DgD4Y7AI5HAzK5BBiIryNCSgVMrVKoaWoMAbqgr1VWNCpnzi8sTSsqkz7kT/6MGcX4u/44K17Hf15SZC9daoZoXH09YnNmcY9ad2+UTGlOkk1/VUiEOTugdk1vcqOZWKhXqll2XIBiXmCSZodsa2eLJqRzcLt1RXzBecK5B4Fhg8ezWIm1ipJnTpDS0T6nlZfYv1FLm6idki4rdqGhAwGf5TYBEQAAOw==";
        private const sou7 : String = "R0lGODlhGAAiALMAAABZAAD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////////yH5BAEAAAEALAAAAAAYACIAAAS8MJRJq7VCyMt7RmAojiRyDGVanmoLHqwJz3Rto7Kt329t/EDDDmczEI5HoY5YQxwPx1yNaUPuYFTa8znsVbldKcxIgBKUPPHBiSSosa/g7wCky5VEgF5v2PP9AHgvegd6CISGiAAyTHszjjCQcCaKhQCWmISTkZqWl5yfm4p9l3+lgaJ+h6qAjF5XV3l+pHu0fKmWq7mKrjKSv50xmafDmJuej52SwqPNp4KUrNJ7vWsuJMewsQFv2jMBEQAAOw==";
        private const sou8 : String = "R0lGODlhGAAiALMAAABZAAD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////////yH5BAEAAAEALAAAAAAYACIAAATMMJRJq7VCyMt7RmAojiRyDGVanmoLHqwJz3Rto7Kt36/h/7WfEIY7AI5HQxCZJL6OCGgtCqDKilEjSGgAAbTXl9HwPZCb47LTdAb8kO+kMmb8JqF3uxoLPxrrbWJFWkxuhVkzRWR/VlJ2PmuASCN9bpGHOV5MYTk7nnSFkDA+oZdVcEKTUnRZX2evf1WcMIaboWp0gX56VG5zRbuntVR1iS+9IZOaspGEMMi0iJGLviOkY79PtXMzr2jAm1OHkSRT5XSfnwMBnek2AREAADs=";
        private const sou9 : String = "R0lGODlhGAAiALMAAABZAAD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////////yH5BAEAAAEALAAAAAAYACIAAATFMJRJq7VCyMt7RmAojiRyDGVanmoLHqwJz3Rto7Kt36/h/8DgD4Y7AI5HA2G5NCCTxNfRCEAsD0vE9CgrUgEz5gxJK27B1+t55iXDxDB31HRWErAEJxga+3KZWU9VczuFZVJPdkx6SAaEZ1Z3gXuDfV9hV3FTbIhUeJ9rhJdvmaOPlHZ4elSOfYKRTFpPXS+GhmaJgHmCrbhUkXiyv6JycKaulJ9qycSbeHeaYJx0qGm7qKdIsJPahC4rlrY7AwE54jYBEQAAOw==";
        private const ton : String = "R0lGODlhGAAiALMAAAAAAAAxYwD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////yH5BAEAAAIALAAAAAAYACIAAAS7UJhJq7VjyMt7TmAojmSCEGVanmoLIqwJz3Rto7Kt3299/IfdDKcDAAg/IbEGMgKEsZ2xp1vajMCdFQZ0PrXUmRcBDNaWWZgXax5SAb+x+ktbNuGINSAchd2NAXc5boMJAIEBZFODMFtNB3BOYIx5XgGBVWFxXpSEM5uGe2w8MqCVdwRIbURIh4aQT39HSUSLJpIICZeXRo0vIX64KX00d1DENb1QWzOhx8x+up2eOsBKfMdnAtPZCAIRAAA7";
        private const chun : String = "R0lGODlhGAAiALMAAAAAAAAxYwD//4RCAISEhKUAAMaEAM7Oztzc3P///////////////////////////yH5BAEAAAIALAAAAAAYACIAAASoUJhJq7VjyMt7TmAojmSCEGVanmoLIqwJz3Rto7Kt369+/DsYzncoAHdDW7FgPCB7tQST6dQlo1Jmrna1aRO/6qxbo/6atGG4ep5OjzGYuV0IvccvkNuNoOeSWV9MfVNQgHpNZl9pUAiBS0t1XI2IewONcTQgl1+YmZqIQZ9eBaJkNINBpzOpT1tlpaqerLGuQa1Ws3KStjpSuqOgr5PDolwCxcYzAhEAADs=";
        
        private const bmparray : Array = [
            man1, man2, man3, man4, man5, man6, man7, man8, man9,
            pin1, pin2, pin3, pin4, pin5, pin6, pin7, pin8, pin9,
            sou1, sou2, sou3, sou4, sou5, sou6, sou7, sou8, sou9,
            ton, nan, sha, pei, haku, hatu, chun
            ];
           private var _map : Array = [];
        private var _handbtns : Array;
        private var _hand : Array;
        
        private var _tfmsg : TextField;
        private var _tftumo : TextField;
        
        private var _handres : Array;
        
        private var _submit : SimpleButton;
        
        public function ShantenTest() {
            _tfmsg = new TextField();
            _tfmsg.border = true;
            addChild(_tfmsg);
            _tfmsg.x = 290;
            _tfmsg.y = 120;
            _tfmsg.width = 160;
            _tfmsg.height = 50;
            
            var i : int;
            var btn : SimpleButton;
            
            _handbtns = [];
            _handres = [];
            _hand = [0, 1, 2, 12, 12, 15, 16, 17, 18, 19, 20, 23, 24, 24];
            
            // 手の例を配置
            for(i = 0;i < _hand.length;i++){
            btn = new SimplerButton(Base64ImageLoader.load(bmparray[_hand[i]]));
            btn.addEventListener(MouseEvent.CLICK, onClickRemove);
            btn.x = 20 + 24 * i;
            btn.y = 20;
            _handbtns.push(btn);
            addChild(btn);
            }
            
            var tfsubmit : TextField = new TextField();
            tfsubmit.autoSize = "left";
            tfsubmit.text = "計算";
            tfsubmit.border = true;
            _submit = new SimplerButton(tfsubmit);
            _submit.x = 290;
            _submit.y = 80;
            addChild(_submit);
            _submit.addEventListener(MouseEvent.CLICK, onSubmit);
              
            var tfclear : TextField = new TextField();
            tfclear.autoSize = "left";
            tfclear.text = "クリア";
            tfclear.border = true;
            var clear : SimpleButton = new SimplerButton(tfclear);
            clear.x = 330;
            clear.y = 80;
            addChild(clear);
            clear.addEventListener(MouseEvent.CLICK, function(e : MouseEvent) : void{
                for each(btn in _handbtns){
                    btn.removeEventListener(MouseEvent.CLICK, onClickRemove);
                    removeChild(btn);
                }
                _handbtns = [];
                _hand = [];
            });
              
            _tftumo = new TextField();
            _tftumo.type = "input";
            _tftumo.autoSize = "left";
            _tftumo.border = true;
            _tftumo.text = "18";
            _tftumo.x = 430;
            _tftumo.y = 80;
            addChild(_tftumo);
            
            var tftumolbl : TextField = new TextField();
            tftumolbl.autoSize = "left";
            tftumolbl.text = "残り自模:";
            tftumolbl.x = 370;
            tftumolbl.y = 80;
            tftumolbl.selectable = false;
            addChild(tftumolbl);
            
            for(i = 0;i < 34;i++){
                btn = new SimplerButton(Base64ImageLoader.load(bmparray[i]));
                btn.x = 30 * (i % 9) + 10;
                btn.y = 80 + 40 * ((i / 9) >> 0);
                addChild(btn);
                _map.push(btn);
                btn.addEventListener(MouseEvent.CLICK, onClickAppend);
            }
        }
        
        private function onSubmit(e : MouseEvent) : void
        {
            if(_hand.length < 14){
                _tfmsg.text = "牌が足りないっす";
                return;
            }
            var tumo : int = int(_tftumo.text);
            if(tumo < 1 || tumo > 18){
                _tfmsg.text = "残り自模数が範囲外っす";
                return;
            }
            
            _submit.enabled = false;
            
            for each(var o : DisplayObject in _handres){
                removeChild(o);
            }
            
            var s : int, g : int;
            s = getTimer();
            
            var st : Shanten = new Shanten();
            var ret : Array = st.enumerate(
                Shanten.encount(Vector.<int>(_hand)),
                Shanten.minus(Shanten.encount(Vector.<int>(_hand))),
                5, tumo);
            
            g = getTimer();
            _tfmsg.text = (g - s) + " ms";
            
//            for each(var r : Object in ret){
//                tf.appendText(Shanten.decount(r.a) + "\t" + r.shanten + "\t" + r.p + "\n");
//            }


            _handres = [];
            for(var i : int = 0;i < 5;i++){
                var resh : Vector.<int> = Shanten.decount(ret[i].a);
                for(var j : int = 0;j < 14;j++){
                    var d : DisplayObjectContainer = Base64ImageLoader.load(bmparray[resh[j]]);
                    d.x = 20 + 24 * j;
                    d.y = 250 + 40 * i;
                    addChild(d);
                    _handres.push(d);
                }
                var tf : TextField = new TextField();
                tf.autoSize = "left";
                tf.x = 370;
                tf.y = 250 + 40 * i;
                
                var stext : String;
                if(ret[i].shanten > 0){
                    stext = ret[i].shanten + "向聴";
                }else if(ret[i].shanten == 0){
                    stext = "聴牌";
                }else{
                    stext = "和了";
                }
                tf.text = stext + " " + ((ret[i].p * 10000) >> 0) / 100 + "%";
                addChild(tf);
                _handres.push(tf);
            }

            _submit.enabled = true;
        }
        
        private function onClickAppend(e : MouseEvent) : void
        {
            var ind : int = _map.indexOf(e.currentTarget);
            var btn : SimpleButton;
            if(_hand.length < 14){
                for each(btn in _handbtns){
                    btn.removeEventListener(MouseEvent.CLICK, onClickRemove);
                    removeChild(btn);
                }
                
                _handbtns = [];
                _hand.push(ind);
                _hand.sort(function(a : int, b : int) : int { return a - b; }, Array.NUMERIC);
                
                for(var i : int = 0;i < _hand.length;i++){
                    btn = new SimplerButton(Base64ImageLoader.load(bmparray[_hand[i]]));
                    btn.addEventListener(MouseEvent.CLICK, onClickRemove);
                    btn.x = 20 + 24 * i;
                    btn.y = 20;
                    _handbtns.push(btn);
                    addChild(btn);
                }
            }
        }
        
        private function onClickRemove(e : MouseEvent) : void
        {
            var ind : int = _handbtns.indexOf(e.currentTarget);
            e.currentTarget.removeEventListener(MouseEvent.CLICK, onClickRemove);
            removeChild(e.currentTarget as SimpleButton);
            _handbtns.splice(ind, 1);
            _hand.splice(ind, 1);
                
            for(var i : int = ind;i < _handbtns.length;i++){
                _handbtns[i].x = 20 + 24 * i;
                _handbtns[i].y = 20;
            }
        }
    }
}

class Shanten
{
    private static const NCK : Array = [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]];
    private static const JSHUN : Array = [
        1, 1, 1, 1, 1, 1, 1, 0, 0, 
        1, 1, 1, 1, 1, 1, 1, 0, 0, 
        1, 1, 1, 1, 1, 1, 1, 0, 0, 
        0, 0, 0, 0, 0, 0, 0];
    private var _npk : Array = null;
    private var _npq : Number;
    private var _mpk : Array = null;
    
    private function prepare(left : Vector.<int>, q : int) : void
    {
        var i : int, l : Number;
        
        _npk = [];
        var m : int = 0;
        for each(var x : int in left)m += x;
        for(i = 0;i < 40;i++){
            var ar : Array = [];
            l = 1.0;
            for(var j : int = 0;j < q + 1;j++){
                ar.push(l);
                l *= (m - i - j);
            }
            _npk.push(ar);
        }
        _npq = _npk[0][q];
        
        _mpk = [];
        l = 1.0;
        for(i = 0;i < q;i++){
            _mpk.push(l);
            l *= (q - i);
        }
    }
    
    public function enumerate(from : Vector.<int>, left : Vector.<int>, n : int, q : int) : Array
    {
        prepare(left, q);
        var ret : Array = [];
        
        var ct : int = 0;
        var targ : Vector.<int> = new Vector.<int>(34);
        
        var i : int;
        var a : int, b : int, c : int, d : int, e : int, f : int, g : int;
        
        // 通常の和了形
        for(i = 0;i <= 15;i++){ // 順子か刻子かのフラグ4組分
            for(a = 0;a < 34;a++){
                if((i & 1) == 0){
                    if(!JSHUN[a])continue;
                    targ[a]++; targ[a + 1]++; targ[a + 2]++;
                }else{
                    targ[a] += 3;
                }
                for(b = a + (i & 1);b < 34;b++){
                    if((i & 2) == 0){
                        if(!JSHUN[b])continue;
                        targ[b]++; targ[b + 1]++; targ[b + 2]++;
                    }else{
                        targ[b] += 3;
                    }
                    if(minusshanten(targ, from) <= 6){ // この時点のtargですでに6向聴以上ならさようなら
                        for(c = b + ((i >> 1) & 1);c < 34;c++){
                            if((i & 4) == 0){
                                if(!JSHUN[c])continue;
                                targ[c]++; targ[c + 1]++; targ[c + 2]++;
                            }else{
                                targ[c] += 3;
                            }
                            if(minusshanten(targ, from) <= 6){
                                for(d = c + ((i >> 2) & 1);d < 34;d++){
                                    if((i & 8) == 0){
                                        if(!JSHUN[d])continue;
                                        targ[d]++; targ[d + 1]++; targ[d + 2]++;
                                    }else{
                                        targ[d] += 3;
                                    }
                                    if(minusshanten(targ, from) <= 6){
                                        for(e = 0;e < 34;e++){
                                            targ[e] += 2;
                                            if(isValid(targ, from, left)){ // 残り牌の数にあっているかどうか
                                                ct++;
                                                judge(ret, targ, from, left, n, q);
                                            }
                                            targ[e] -= 2;
                                        }
                                    }
                                    if((i & 8) == 0){
                                        if(noShun(d))continue;
                                        targ[d]--; targ[d + 1]--; targ[d + 2]--;
                                    }else{
                                        targ[d] -= 3;
                                    }
                                }
                            }
                            if((i & 4) == 0){
                                if(noShun(c))continue;
                                targ[c]--; targ[c + 1]--; targ[c + 2]--;
                            }else{
                                targ[c] -= 3;
                            }
                        }
                    }
                    if((i & 2) == 0){
                        if(noShun(b))continue;
                        targ[b]--; targ[b + 1]--; targ[b + 2]--;
                    }else{
                        targ[b] -= 3;
                    }
                }
                if((i & 1) == 0){
                    if(noShun(a))continue;
                    targ[a]--; targ[a + 1]--; targ[a + 2]--;
                }else{
                    targ[a] -= 3;
                }
            }
        }
        
        // 七対子形
        for(a = 0;a < 34;a++){
            targ[a] += 2;
            for(b = a + 1;b < 34;b++){
                targ[b] += 2;
                for(c = b + 1;c < 34;c++){
                    targ[c] += 2;
                    if(minusshanten(targ, from) <= 6){
                        for(d = c + 1;d < 34;d++){
                            targ[d] += 2;
                            if(minusshanten(targ, from) <= 6){
                                for(e = d + 1;e < 34;e++){
                                    targ[e] += 2;
                                    if(minusshanten(targ, from) <= 6){
                                        for(f = e + 1;f < 34;f++){
                                            targ[f] += 2;
                                            if(minusshanten(targ, from) <= 6){
                                                for(g = f + 1;g < 34;g++){
                                                    targ[g] += 2;
                                                    if(isValid(targ, from, left)){
                                                        ct++;
                                                        judge(ret, targ, from, left, n, q);
                                                    }
                                                    targ[g] -= 2;
                                                }
                                            }
                                            targ[f] -= 2;
                                        }
                                    }
                                    targ[e] -= 2;
                                }
                            }
                            targ[d] -= 2;
                        }
                    }
                    targ[c] -= 2;
                }
                targ[b] -= 2;
            }
            targ[a] -= 2;
        }
        
        // 国士無双形
        var KOKUSHI : Array = [0, 8, 9, 17, 18, 26, 27, 28, 29, 30, 31, 32, 33];
        for each(a in KOKUSHI)targ[a] = 1;
        for each(a in KOKUSHI){
            targ[a]++;
            if(isValid(targ, from, left)){
                ct++;
                judge(ret, targ, from, left, n, q);
            }
            targ[a]--;
        }
        
        return ret;
    }
    
    private static function noShun(a : int) : Boolean {
        return a == 7 || a == 8 || a == 16 || a == 17 || a >= 25;
    }
    
    private static function isValid(targ : Vector.<int>, from : Vector.<int>, left : Vector.<int>) : Boolean {
        for(var i : int = 0;i < 34;i++){
            if(targ[i] - from[i] > left[i])return false;
        }
        return true;
    }
    
    private function judge(ranks : Array, targ : Vector.<int>, from : Vector.<int>, left : Vector.<int>, n : int, q : int) : void
    {
        var r : Object = calc(targ, from, left, q);
        if(r == null)return;
        
        var i : int = 0;
        for(i = ranks.length - 1;i >= 0 && r.p >= ranks[i].p;i--);
        if(i + 1 == n)return;
        
        r.a = targ.concat();
        ranks.splice(i + 1, 0, r);
        if(ranks.length > n)ranks.pop();
    }
    
    private function minusshanten(targ : Vector.<int>, from : Vector.<int>) : int
    {
        var shanten : int = 0;
        for(var i : int = 0;i < 34;i++){
            if(targ[i] > from[i]){
                shanten += targ[i] - from[i];
            }    
        }
        return shanten;
    }
    
    private function calc(targ : Vector.<int>, from : Vector.<int>, left : Vector.<int>, q : int) : Object
    {
        var shanten : int = 0;
        var shantenN : int = 0;
        var upper : int = 1;
        for(var i : int = 0;i < 34;i++){
            if(targ[i] > from[i]){
                var d : int = targ[i] - from[i];
                shanten += d;
                shantenN += left[i];
                if(shanten >= 6)return null;
                upper *= NCK[left[i]][d];
            }
        }
        
        var p : Number = upper * _mpk[shanten] / (_npq / _npk[shantenN][q - shanten]);
        return {shanten : shanten - 1, p : p};
    }
    
    public function calcP(targ : Vector.<int>, from : Vector.<int>, left : Vector.<int>, q : int) : Number
    {
        prepare(left, q);
        
        var shanten : int = 0;
        var shantenN : int = 0;
        var upper : int = 1;
        for(var i : int = 0;i < 34;i++){
            if(targ[i] > from[i]){
                var d : int = targ[i] - from[i];
                shanten += d;
                shantenN += left[i];
                upper *= NCK[left[i]][d];
            }
        }
        
        return upper * _mpk[shanten] / (_npq / _npk[shantenN][q - shanten]);
    }
    
    public static function encount(a : Vector.<int>) : Vector.<int>
    {
        var ret : Vector.<int> = new Vector.<int>(34);
        for each(var x : int in a)ret[x]++;
        return ret;
    }
    
    public static function decount(a : Vector.<int>) : Vector.<int>
    {
        var ret : Vector.<int> = new Vector.<int>();
        for(var i : int = 0;i < a.length;i++){
            for(var j : int = 0;j < a[i];j++)ret.push(i);
        }
        return ret;
    }
    
    public static function minus(a : Vector.<int>) : Vector.<int>
    {
        var ret : Vector.<int> = new Vector.<int>();
        for each(var x : int in a){
            ret.push(4 - x);
        }
        return ret;
    }

}

/**
 * Base64化された画像データを表示可能な形式に変換するクラス
 * 
 * 使い方 :
 * var data:String = "Base64化された画像データ";
 * var display:DisplayObjectContainer = Base64ImageLoader.load(data);
 * if (display != null)
 *     addChild(display);
 */
class Base64ImageLoader
{
    import flash.display.DisplayObjectContainer;
    import flash.display.Loader;
    import flash.utils.ByteArray;
    import mx.utils.Base64Decoder;
    static public function load(data:String):DisplayObjectContainer
    {
        var byteArray:ByteArray;
        var base64Decoder:Base64Decoder;
        var loader:Loader;
        
        base64Decoder = new Base64Decoder();
        base64Decoder.decode(data);
        
        try {
            byteArray = base64Decoder.toByteArray();
            byteArray.position = 0;
        } catch (e:Error) {
            return null;
        }
        
        loader = new Loader();
        loader.loadBytes(byteArray);
        
        return loader;
    }
}

import flash.display.*;

class SimplerButton extends SimpleButton
{
    public function SimplerButton(d : DisplayObject)
    {
         this.upState = d;
         this.overState = d;
         this.downState = d;
         this.hitTestState = d;
    }
}