#awk -f rhawk < testirc.txt
#awk -f rhawk < testirc.txt
awk -f test.awk test.txt \
- | awk '-vDEBUG=1' -frhawk 2>&1 \
- | grep -v '^ >\|USER\|NICK\|CAP\|JOIN\|TOPIC\|WHO\|unicode'
- #| grep 'points\|bid\|took'
+ | awk '-vDEBUG=1' -frhawk 2>&1 1>/dev/null \
+ | grep -v '^ > \(USER\|NICK\|CAP\|JOIN\|TOPIC\|WHO\)' \
+ | grep -v '^ . .*\(ACCOUNT\|IDENTIFY\|unicode\|colors\)' \
+ | sed -e 's/^ > PRIVMSG #\w* :/rhawk:\t/' \
+ -e 's/^ < :\([^!]*\)![^ ]* PRIVMSG #\w* :/\1:\t/ '
test-select:Q: select.so
#awk -f select.awk
delete sp_hands # [p] Each players cards
delete sp_players # [p] Player names players["name"] -> i
delete sp_auths # [c] Player auth names auths["auth"] -> "name"
+ delete sp_share # [c] Player teammates share["friend"] -> "name"
delete sp_order # [i] Player order order[i] -> "name"
delete sp_scores # [i] Teams score
}
json_copy(game, "hands", sp_hands);
json_copy(game, "players", sp_players);
json_copy(game, "auths", sp_auths);
+ json_copy(game, "share", sp_share);
json_copy(game, "order", sp_order);
json_copy(game, "scores", sp_scores);
sp_acopy(sp_hands, game["hands"]);
sp_acopy(sp_players, game["players"]);
sp_acopy(sp_auths, game["auths"]);
+ sp_acopy(sp_share, game["share"]);
sp_acopy(sp_order, game["order"]);
sp_acopy(sp_scores, game["scores"]);
}
}
// {
- sp_from = AUTH in sp_auths ? sp_auths[AUTH] : FROM
+ sp_from = AUTH in sp_auths ? sp_auths[AUTH] : \
+ AUTH in sp_share ? sp_share[AUTH] : FROM
sp_valid = sp_from && sp_from == sp_player
}
sp_deal()
}
+/^\.allow \S+$/ {
+ _who = $2 in USERS ? USERS[$2]["auth"] : ""
+ _str = _who && _who != $2 ? $2 " (" _who ")" : $2
+ if (sp_state ~ "new|join") {
+ reply("The game has not yet started")
+ }
+ else if (!(sp_from in sp_players)) {
+ reply("You are not playing")
+ }
+ else if (!_who) {
+ reply(_str " is not logged in")
+ }
+ else if (_who in sp_players || _who in sp_auths) {
+ reply(_str " is a primary player")
+ }
+ else if (_who in sp_share) {
+ reply(_str " is already playing for " sp_share[_who])
+ }
+ else {
+ reply(_str " can now play for " sp_from)
+ sp_share[_who] = sp_from
+ }
+}
+
+/^\.deny \S+$/ {
+ _who = $2 in USERS ? USERS[$2]["auth"] : $2
+ _str = _who && _who != $2 ? $2 " (" _who ")" : $2
+ if (sp_state ~ "new|join") {
+ reply("The game has not yet started")
+ }
+ else if (!(sp_from in sp_players)) {
+ reply("You are not playing")
+ }
+ else if (_who in sp_players || _who in sp_auths) {
+ reply(_str " is a primary player")
+ }
+ else if (!(_who in sp_share) || sp_share[_who] != sp_from) {
+ reply(_str " is not playing for " sp_from)
+ }
+ else {
+ reply(_str " can no longer play for " sp_from)
+ delete sp_share[_who]
+ }
+}
+
+sp_state ~ "(bid|pass|play)" &&
+/^\.show/ {
+ for (_i in sp_share)
+ say(_i " can play for " sp_share[_i]);
+}
+
!sp_valid &&
(sp_state == "bid" || sp_state == "play") &&
/^\.(bid|play)\>/ {
print ":" who"!u@h PRIVMSG #rhtest :" msg
}
+function auth(user, nick)
+{
+ print ":" nick "!u@c ACCOUNT " user
+}
+
function error(msg)
{
print "error: " msg > "/dev/stderr"
function command(who, cmd)
{
arg=cmd
- gsub(/\<[nbp]|[+-]/, "", arg)
+ gsub(/\<[nbpYNS]|[+-]/, "", arg)
if (cmd ~ /^\./) 0 # nop
else if (cmd ~ /^n/) say(who, ".newgame " arg)
else if (cmd ~ /^e/) say(who, ".endgame ")
else if (cmd ~ /^j/) say(who, ".join")
+ else if (cmd ~ /^Y/) say(who, ".allow " arg)
+ else if (cmd ~ /^N/) say(who, ".deny " arg)
+ else if (cmd ~ /^S/) say(who, ".show ")
else if (cmd ~ /^d/) say("andy753421", ".deal " who " " hand[who])
else if (cmd ~ /^l/) say(who, ".look")
else if (cmd ~ /^b/) say(who, ".bid " arg)
}
# Rules
-BEGIN { reset() }
+BEGIN {
+ auth("andy753421", "andy753421")
+ reset()
+}
// { gsub(/#.*/, "") }
/^[^ ]+:/ {
- gsub(/:/, "")
+ gsub(/:/, " ")
+ split($1, parts, "/");
pi = length(players)
if (NF-2 > nturns)
nturns = NF-1
for (i=2; i<=NF; i++)
turns[pi][i-2] = $i
- players[pi] = $1
- hand[$1] = $0
- gsub(/^\w*|[nbp-]\w+|\<[nejlbsBtpd]\>|[.+]/, "", hand[$1])
- gsub(/^ */, "", hand[$1])
- print $1 ": " hand[$1] > "/dev/stderr"
- say($1, "unicode :(")
+ who = parts[1]
+ players[pi] = parts[1]
+ auths[pi] = parts[2]
+ hand[who] = $0
+ gsub(/^\w*(\/\w*)?|[nbpYN-]\w+|\<[nejadwlbsBtpdS]\>|[.+]/, "", hand[who])
+ gsub(/^ */, "", hand[who])
+ print who ": " hand[who] > "/dev/stderr"
+ say(who, "unicode :(")
+ say(who, "colors :(")
}
/^\s*$/ {
+ for (pi=0; pi<length(players); pi++)
+ if (auths[pi])
+ auth(auths[pi], players[pi])
for (ti=0; ti<nturns; ti++)
for (pi=0; pi<length(players); pi++)
command(players[pi], turns[pi][ti])
# nn - newgame to n
# e - endgame
# j - join
+# Y - allow
+# N - deny
+# S - show
+# d - deal
# l - look
# bn - bid n
# s - score
# B - bids
# t - tricks
-# t - tricks
# T - turn
# pn - pass card n
# card - play card
# -card - play but don't add to deck
# +card - add to deck but don't play
+# Test allow / deny
+# .- The game has not yet started
+# | .- You are not playing
+# | |- Is a primary player
+# | |- Is not logged in
+# | |- Can now playing for
+# | |- Is already playing for
+# | | .- You are not playing
+# | | |- Is a primary player
+# | | |- Is not playing for
+# | | |- Can no longer play
+# | | |- Is not playing for
+auth/auth: . . . . . . . -As
+nope: . . Yauth Nauth . . . .
+a/aa: n . Ya Na d b1 Yauth +As
+b/bb: Ynewgame j Ynope Nnope d b1 . Ah
+c/cc: Nnewgame j Yauth Nauth d b1 . Ad
+d/dd: . j Yauth Nauth d b1 . Ac
+
# Test scoring
-x: s s s s s s s s s s s s
-x: B B B B B B B B B B B B
-x: t t t t t t t t t t t t
-x: T T T T T T T T T T T T
-A: n j . . . d b3 . . . As .
-b: . . j . . d . b3 . . Ah .
-c: . . . j . d . . b3 . Ad .
-d: . . . . j d . . . b3 Ac .
+#x: s s s s s s s s s s s s
+#x: B B B B B B B B B B B B
+#x: t t t t t t t t t t t t
+#x: T T T T T T T T T T T T
+#A: n j . . . d b3 . . . As .
+#b: . . j . . d . b3 . . Ah .
+#c: . . . j . d . . b3 . Ad .
+#d: . . . . j d . . . b3 Ac .
# Nil/blind
#a: n j d l b0 . . As Ks Qs Js 10s 9s 8s 7s 6s 5s 4s 3s 2s t e