3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-30 07:59:42 +01:00

Connect4: fix code indentation and whitespace

This commit is contained in:
Pragmatic Software 2018-07-07 15:04:02 -07:00
parent bf5a9b2d46
commit 67ab8920e9

View File

@ -138,18 +138,18 @@ sub connect4_cmd {
$self->{N_Y} = (not length $4) ? 6 : $4; $self->{N_Y} = (not length $4) ? 6 : $4;
$self->{CONNECTIONS} = (not length $1) ? 4 : $1; $self->{CONNECTIONS} = (not length $1) ? 4 : $1;
if ((not length $2) && ($self->{CONNECTIONS} >= $self->{N_X} || $self->{CONNECTIONS} >= $self->{N_Y})) { if ((not length $2) && ($self->{CONNECTIONS} >= $self->{N_X} || $self->{CONNECTIONS} >= $self->{N_Y})) {
$self->{N_X} = $self->{CONNECTIONS} * 2 - 1; $self->{N_X} = $self->{CONNECTIONS} * 2 - 1;
$self->{N_Y} = $self->{CONNECTIONS} * 2 - 2; $self->{N_Y} = $self->{CONNECTIONS} * 2 - 2;
} }
if ($self->{N_X} > 32 || $self->{N_X} < $self->{CONNECTIONS}) { if ($self->{N_X} > 32 || $self->{N_X} < $self->{CONNECTIONS}) {
return "Wrong board-X size"; return "Wrong board-X size";
} }
if ($self->{N_Y} > 32 || $self->{N_Y} < $self->{CONNECTIONS}) { if ($self->{N_Y} > 32 || $self->{N_Y} < $self->{CONNECTIONS}) {
return "Wrong board-Y size"; return "Wrong board-Y size";
} }
my $id = $self->{pbot}->{messagehistory}->{database}->get_message_account($nick, $user, $host); my $id = $self->{pbot}->{messagehistory}->{database}->get_message_account($nick, $user, $host);
my $player = { id => $id, name => $nick, missedinputs => 0 }; my $player = { id => $id, name => $nick, missedinputs => 0 };
@ -158,7 +158,7 @@ sub connect4_cmd {
$player = { id => -1, name => undef, missedinputs => 0 }; $player = { id => -1, name => undef, missedinputs => 0 };
push @{$self->{state_data}->{players}}, $player; push @{$self->{state_data}->{players}}, $player;
return "/msg $self->{channel} $nick has made an open challenge (Connect-$self->{CONNECTIONS} @ " . return "/msg $self->{channel} $nick has made an open challenge (Connect-$self->{CONNECTIONS} @ " .
"$self->{N_X}x$self->{N_Y} board)! Use `accept` to accept their challenge."; "$self->{N_X}x$self->{N_Y} board)! Use `accept` to accept their challenge.";
} }
my $challengee = $self->{pbot}->{nicklist}->is_present($self->{channel}, $arguments); my $challengee = $self->{pbot}->{nicklist}->is_present($self->{channel}, $arguments);
@ -172,22 +172,22 @@ sub connect4_cmd {
if (length $options) { if (length $options) {
if ($options =~ m/^([3-9])(:(\d+)x(\d+))?$/) { if ($options =~ m/^([3-9])(:(\d+)x(\d+))?$/) {
$self->{N_X} = (not length $3) ? 7 : $3; $self->{N_X} = (not length $3) ? 7 : $3;
$self->{N_Y} = (not length $4) ? 6 : $4; $self->{N_Y} = (not length $4) ? 6 : $4;
$self->{CONNECTIONS} = (not length $1) ? 4: $1; $self->{CONNECTIONS} = (not length $1) ? 4: $1;
if ((not length $2) && ($self->{CONNECTIONS} >= $self->{N_X} || $self->{CONNECTIONS} >= $self->{N_Y})) { if ((not length $2) && ($self->{CONNECTIONS} >= $self->{N_X} || $self->{CONNECTIONS} >= $self->{N_Y})) {
$self->{N_X} = $self->{CONNECTIONS} * 2 - 1; $self->{N_X} = $self->{CONNECTIONS} * 2 - 1;
$self->{N_Y} = $self->{CONNECTIONS} * 2 - 2; $self->{N_Y} = $self->{CONNECTIONS} * 2 - 2;
} }
if ($self->{N_X} > 32 || $self->{N_X} < $self->{CONNECTIONS}) { if ($self->{N_X} > 32 || $self->{N_X} < $self->{CONNECTIONS}) {
return "Wrong board-X size"; return "Wrong board-X size";
} }
if ($self->{N_Y} > 32 || $self->{N_Y} < $self->{CONNECTIONS}) { if ($self->{N_Y} > 32 || $self->{N_Y} < $self->{CONNECTIONS}) {
return "Wrong board-Y size"; return "Wrong board-Y size";
} }
} else { return "wrong options: '$options'; use <C:ROWSxCOLS>"; } } else { return "wrong options: '$options'; use <C:ROWSxCOLS>"; }
} }
@ -201,7 +201,7 @@ sub connect4_cmd {
push @{$self->{state_data}->{players}}, $player; push @{$self->{state_data}->{players}}, $player;
return "/msg $self->{channel} $nick has challenged $challengee to " . return "/msg $self->{channel} $nick has challenged $challengee to " .
"Connect-$self->{CONNECTIONS} @ $self->{N_X}x$self->{N_Y} board! Use `accept` to accept their challenge."; "Connect-$self->{CONNECTIONS} @ $self->{N_X}x$self->{N_Y} board! Use `accept` to accept their challenge.";
} }
when ('accept') { when ('accept') {
@ -653,9 +653,9 @@ sub column_top {
my $y; my $y;
for ($y = 0; $y < $self->{N_Y}; $y++) { for ($y = 0; $y < $self->{N_Y}; $y++) {
if ($self->{board}->[$y][$x] ne ' ') { if ($self->{board}->[$y][$x] ne ' ') {
return $y - 1; return $y - 1;
} }
} }
return -1; # shouldnt happen return -1; # shouldnt happen
} }
@ -727,21 +727,21 @@ sub show_board {
for ($y = 0; $y < $self->{N_Y}; $y++) { for ($y = 0; $y < $self->{N_Y}; $y++) {
for ($x = 0; $x < $self->{N_X}; $x++) { for ($x = 0; $x < $self->{N_X}; $x++) {
$chip = $self->{board}->[$y][$x]; $chip = $self->{board}->[$y][$x];
my $rc = "$y, $x"; my $rc = "$y, $x";
$c = $chip eq 'O' ? $color{red} : $color{yellow}; $c = $chip eq 'O' ? $color{red} : $color{yellow};
if (grep(/^$rc$/, @{$self->{winner_line}})) { if (grep(/^$rc$/, @{$self->{winner_line}})) {
$c .= $color{bold}; $c .= $color{bold};
} }
$buf .= "$color{blue}\[$c$chip$color{blue}]$color{reset}"; $buf .= "$color{blue}\[$c$chip$color{blue}]$color{reset}";
} }
$buf .= "\n"; $buf .= "\n";
} }
foreach my $line (split /\n/, $buf) { foreach my $line (split /\n/, $buf) {
$self->send_message($self->{channel}, $line); $self->send_message($self->{channel}, $line);
} }
} }