Skip to content

Commit 874b978

Browse files
committed
・__constructの無駄な引数を削除
・トーナメントの生成メソッドをオーソドックスな形になる物に修正。
1 parent a618b49 commit 874b978

File tree

1 file changed

+107
-35
lines changed

1 file changed

+107
-35
lines changed

bot/ranbat.class.inc

+107-35
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ class Tournament extends common_base implements Game{
446446
var $game_title;
447447
var $scheduler_id;
448448
var $conn;
449-
function __construct($args){
449+
function __construct(){
450450
$this->player = Array();
451451
$this->table = Array();
452452
$this->winner = Array();
@@ -458,7 +458,8 @@ class Tournament extends common_base implements Game{
458458
$this->player[$entry[name]] = new Player( $entry );
459459
}
460460

461-
function lot2(){
461+
function lot(){
462+
//初期実装
462463
if( !$this->current ){
463464
$this->battle_cnt = 0;
464465
$l = array_keys($this->player);
@@ -480,11 +481,12 @@ class Tournament extends common_base implements Game{
480481
}
481482

482483
function start(){
483-
$this->lot();
484+
$this->lot3();
484485
return $this->getTableString('long');
485486
}
486487

487-
private function lot(){
488+
private function lot2(){
489+
//1回戦で出来るだけ対戦を行なうモード
488490
if( !$this->current ){
489491
$this->battle_cnt = 0;
490492
$l = array_keys($this->player);
@@ -522,6 +524,31 @@ class Tournament extends common_base implements Game{
522524
}
523525
}
524526

527+
///オーソドックスなトーナメント
528+
private function lot3(){
529+
if( !$this->current ){
530+
$this->battle_cnt = 0;
531+
$l = array_keys($this->player);
532+
shuffle($l);
533+
534+
$lengh = count($l);
535+
for($s=1;$lengh>$s<<1;$s=$s<<1);
536+
537+
$new = Array( $l );
538+
539+
while( true ){
540+
$current = array();
541+
foreach( $new as $card ){
542+
list($current[],$current[]) = array_chunk( $card, ceil(count($card)/2) );
543+
}
544+
$new = $current;
545+
if( $s <= count($new) ){break;}
546+
}
547+
548+
$this->table[$this->current] = array_reverse($new);
549+
}
550+
}
551+
525552
function win($name){
526553
if( !isset($this->player[$name]) ){ return RANBAT_PRIV_CANCEL_ERROR;}
527554

@@ -590,38 +617,80 @@ class Tournament extends common_base implements Game{
590617

591618
function getTableString( $type = 'short' ){
592619
if( !count( $this->table ) ){
593-
$this->lot();
620+
$this->lot2();
594621
}
595622
$array = Array();
596623

597-
$cnt = count($this->table[$this->current]);
598-
$str = '';
599-
if( $cnt == 1 ){
600-
$str .= '決勝';
601-
}else if( $cnt == 2 ){
602-
$str .= '準決勝';
603-
}else{
604-
$str .= ($this->current+1).'回戦';
605-
}
606-
$array[] = $str;
607-
$i=0;
608-
foreach( $this->table[$this->current] as $key => $match ){
609-
$str = ++$i.':';
610-
switch(count($match)){
611-
case 2:
612-
$str .= $match[0].' vs '.$match[1];
613-
if( isset( $this->winner[ $key ] ) ){
614-
$str .= '(win:'.$this->winner[$key].')';
624+
switch( $type ){
625+
case 'html':
626+
$cnt = count($this->table[$this->current]);
627+
$str = '';
628+
if( $cnt == 1 ){
629+
$str .= '決勝';
630+
}else if( $cnt == 2 ){
631+
$str .= '準決勝';
632+
}else{
633+
$str .= ($this->current+1).'回戦';
634+
}
635+
$array[] = $str;
636+
$i=0;
637+
foreach( $this->table[$this->current] as $key => $match ){
638+
$str = ++$i.':';
639+
switch(count($match)){
640+
case 2:
641+
if( !isset( $this->winner[ $key ] ) ){
642+
$str .= $match[0].' vs '.$match[1];
643+
}else{
644+
if( $this->winner[ $key ] == $match[0] ){
645+
$str .= '<span class="winner" >'.$match[0].'</span> vs '.$match[1];
646+
}else{
647+
$str .= $match[0].' vs <span class="winner" >'.$match[1].'</span>';
648+
}
649+
}
650+
break;
651+
case 1:
652+
$str .= 'seed:'.$match[0];
653+
break;
654+
case 0:
655+
continue 2;
656+
//$str .= ' ';
657+
break;
615658
}
616-
break;
617-
case 1:
618-
$str .= 'seed:'.$match[0];
619-
break;
620-
case 0:
621-
$str .= ' ';
622-
break;
623-
}
624-
$array[] = $str;
659+
$array[] = $str;
660+
}
661+
break;
662+
default:
663+
$cnt = count($this->table[$this->current]);
664+
$str = '';
665+
if( $cnt == 1 ){
666+
$str .= '決勝';
667+
}else if( $cnt == 2 ){
668+
$str .= '準決勝';
669+
}else{
670+
$str .= ($this->current+1).'回戦';
671+
}
672+
$array[] = $str;
673+
$i=0;
674+
foreach( $this->table[$this->current] as $key => $match ){
675+
$str = ++$i.':';
676+
switch(count($match)){
677+
case 2:
678+
$str .= $match[0].' vs '.$match[1];
679+
if( isset( $this->winner[ $key ] ) ){
680+
$str .= '(win:'.$this->winner[$key].')';
681+
}
682+
break;
683+
case 1:
684+
$str .= 'seed:'.$match[0];
685+
break;
686+
case 0:
687+
continue;
688+
//$str .= ' ';
689+
break;
690+
}
691+
$array[] = $str;
692+
}
693+
break;
625694
}
626695
return join("\n",$array);
627696
}
@@ -777,7 +846,7 @@ class Kohaku extends common_base implements Game{
777846
}
778847

779848
function setPlayer($name,$nick){
780-
if( $nick != $this->team[$this->wait_leader]['leader']['nick'] && array_search( $nick,Array('swirhen','tyoro') ) === FALSE ){
849+
if( $nick != $this->team[$this->wait_leader]['leader']['nick'] && array_search( $nick,Array('swirhen','tyoro','tuskdon') ) === FALSE ){
781850
return;
782851
}
783852
if( is_numeric( $name ) && isset( $this->num_list[$name] ) ){
@@ -1018,7 +1087,10 @@ class Kohaku extends common_base implements Game{
10181087
}
10191088
$str .= "\n";
10201089
break;
1021-
case 'uragiri':
1090+
/*case 'html':
1091+
1092+
break;
1093+
*/case 'uragiri':
10221094
$l = Array();
10231095
$this->num_list = Array();
10241096
$i = 1;
@@ -1142,7 +1214,7 @@ class GameLog{
11421214
function end( $state = self::GAME_STATUS_END ){
11431215
if( !is_null( $this->game_id ) ){
11441216
$record['status'] = $state;
1145-
$record['data'] = '';
1217+
//$record['data'] = '';
11461218
$this->conn->AutoExecute( 'games', $record, 'UPDATE', 'id = '.$this->game_id );
11471219
}
11481220
}

0 commit comments

Comments
 (0)