Skip to content

Commit

Permalink
出牌检测
Browse files Browse the repository at this point in the history
  • Loading branch information
mailgyc-163 committed Jul 9, 2017
1 parent 9212ad8 commit cf37b1c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 49 deletions.
6 changes: 3 additions & 3 deletions src/core/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def from_server(self, packet):
elif code == Pt.RSP_CALL_SCORE:
if self.table.turn_player == self:
# caller = packet[1]
score = packet[2]
# score = packet[2]
call_end = packet[3]
if not call_end:
self.auto_call_score(score)
self.auto_call_score()
else:
self.auto_shot_poker()
elif code == Pt.RSP_SHOW_POKER:
Expand All @@ -57,7 +57,7 @@ def from_server(self, packet):
def auto_call_score(self, score=0):
# millis = random.randint(1000, 2000)
# score = random.randint(min_score + 1, 3)
packet = [Pt.REQ_CALL_SCORE, score + 1]
packet = [Pt.REQ_CALL_SCORE, self.table.call_score + 1]
IOLoop.current().add_callback(self.to_server, packet)

def auto_shot_poker(self):
Expand Down
6 changes: 3 additions & 3 deletions src/core/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def _to_cards(pokers):


def _to_poker(card):
if card == 'w':
return [52]
if card == 'W':
return [52]
if card == 'w':
return [53]

cards = 'A234567890JQK'
Expand Down Expand Up @@ -149,5 +149,5 @@ def _card_type(cards):
if value >= 0:
return t, value
logger.info('Unknown Card Type: %s', cards)
raise Exception('Unknown Card Type: %s' % cards)
# raise Exception('Unknown Card Type: %s' % cards)
return '', 0
3 changes: 2 additions & 1 deletion src/static/js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ PG.Game.prototype = {
turnPlayer.pushAPoker(poker);
}
turnPlayer.sortPoker();
turnPlayer.arrangePoker();
if (this.whoseTurn == 0) {
turnPlayer.arrangePoker();
for (var i = 0; i < 3; i++) {
var p = this.tablePoker[i + 3];
var tween = this.game.add.tween(p).to({y: this.game.world.height - PG.PH * 0.8 }, 400, Phaser.Easing.Default, true);
Expand All @@ -210,6 +210,7 @@ PG.Game.prototype = {
for (var i = 0; i < 3; i++) {
var p = this.tablePoker[i + 3];
p.frame = 54;
p.frame = 54;
this.game.add.tween(p).to({ x: first.x, y: first.y}, 200, Phaser.Easing.Default, true);
}
}
Expand Down
30 changes: 18 additions & 12 deletions src/static/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,8 @@ PG.Player.prototype.onShot = function (btn) {
return;
}
var code = this.canPlay(this.game.isLastShotPlayer() ? [] : this.game.tablePoker, this.hintPoker);
if (code == -1) {
this.say("出牌不符合规矩");
return;
}
if (code == 0) {
this.say("出牌必须大于上家的牌");
if (code) {
this.say(code);
return;
}
this.game.finishPlay(this.hintPoker);
Expand All @@ -171,13 +167,23 @@ PG.Player.prototype.hint = function (lastTurnPoker) {

PG.Player.prototype.canPlay = function (lastTurnPoker, shotPoker) {
var cardsA = PG.Poker.toCards(shotPoker);
var valueA = PG.Rule.cardsValue(cardsA);
if (!valueA[0]){
return '出牌不合法';
}
var cardsB = PG.Poker.toCards(lastTurnPoker);
var code = PG.Rule.compare(cardsA, cardsB);
if (code === -10000)
return -1;
if (code > 0)
return 1;
return 0;
if (cardsB.length == 0) {
return '';
}
var valueB = PG.Rule.cardsValue(cardsB);
if (valueA[0] != valueB[0] && valueA[1] < 1000) {
return '出牌类型跟上家不一致';
}

if (valueA[1] > valueB[1]) {
return '';
}
return '出牌需要大于上家';
};

PG.Player.prototype.playPoker = function (lastTurnPoker) {
Expand Down
47 changes: 23 additions & 24 deletions src/static/js/player_net.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@ PG.NetPlayer.prototype.pushAPoker = function (poker) {
};

PG.NetPlayer.prototype.removeAPoker = function (pid) {
if (pid > 53) {
this.pokerInHand.pop();
this._pokerPic.pop();
this.updateLeftPoker();
} else {
for (var i = 0; i < this.pokerInHand.length; i++) {
if (this.pokerInHand[i] === pid) {
this.pokerInHand.splice(i, 1);
}
for (var i = this.pokerInHand.length - 1; i >= 0; i--) {
if (this.pokerInHand[i] === pid) {
this.pokerInHand.splice(i, 1);
break
}
for (var i = 0; i < this._pokerPic.length; i++) {
if (this._pokerPic[i].id === pid) {
this._pokerPic.splice(i, 1);
return;
}
}
if (i == -1) {
this.pokerInHand.pop();
}
for (var i = this._pokerPic.length - 1; i >= 0; i--) {
if (this._pokerPic[i].id === pid) {
this._pokerPic.splice(i, 1);
break
}
console.log('Error: REMOVE POKER ', pid);
}
if (i == -1) {
this._pokerPic.pop();
}
this.updateLeftPoker();
};

PG.NetPlayer.prototype.arrangePoker = function () {
Expand All @@ -44,6 +45,9 @@ PG.NetPlayer.prototype.replacePoker = function (pokers, start) {
if (this.pokerInHand.length !== pokers.length - start) {
console.log("ERROR ReplacePoker:", this.pokerInHand, pokers);
}
if (this._pokerPic.length !== pokers.length - start) {
console.log("ERROR ReplacePoker:", this._pokerPic, pokers);
}
var length = this.pokerInHand.length;
for (var i = 0; i < length; i++) {
this.pokerInHand[i] = pokers[start + i];
Expand All @@ -53,17 +57,12 @@ PG.NetPlayer.prototype.replacePoker = function (pokers, start) {
};

PG.NetPlayer.prototype.findAPoker = function (pid) {
if (pid > 53) {
return this._pokerPic[this._pokerPic.length - 1];
} else {
for (var i = 0; i < this._pokerPic.length; i++) {
if (this._pokerPic[i].id == pid) {
return this._pokerPic[i];
}
for (var i = this._pokerPic.length - 1; i >= 0; i--) {
if (this._pokerPic[i].id == pid) {
return this._pokerPic[i];
}
console.log('Error NetPlayer FindPoker:', pid);
return null;
}
return this._pokerPic[this._pokerPic.length - 1];
};

PG.NetPlayer.prototype.reDealPoker = function () {
Expand Down
11 changes: 5 additions & 6 deletions src/static/js/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ PG.Poker.comparePoker = function (a, b) {
};

PG.Poker.toCards = function (pokers) {

var cards = [];
for (var i = 0; i < pokers.length; i++) {
var pid = pokers[i];
Expand Down Expand Up @@ -125,9 +124,9 @@ PG.Rule.bestShot = function (handCards) {

handCards.sort(this.sorter);
var shot = '';
var len = this.cardsType.length;
var len = this._CardsType.length;
for (var i = 2; i < len; i++) {
var oneRule = PG.RuleList[this.cardsType[i]];
var oneRule = PG.RuleList[this._CardsType[i]];
for (var j = 0; j < oneRule.length; j++) {
if (oneRule[j].length > shot.length && this.containsAll(handCards, oneRule[j])) {
shot = oneRule[j];
Expand All @@ -149,7 +148,7 @@ PG.Rule.bestShot = function (handCards) {
return shot;
};

PG.Rule.cardsType = [
PG.Rule._CardsType = [
'rocket', 'bomb',
'single', 'pair', 'trio', 'trio_pair', 'trio_single',
'seq_single5', 'seq_single6', 'seq_single7', 'seq_single8', 'seq_single9', 'seq_single10', 'seq_single11', 'seq_single12',
Expand Down Expand Up @@ -202,9 +201,9 @@ PG.Rule.cardsValue = function (cards) {
if (index >= 0)
return ['bomb', 1000 + index];

var length = this.cardsType.length;
var length = this._CardsType.length;
for (var i = 2; i < length; i++) {
var typeName = this.cardsType[i];
var typeName = this._CardsType[i];
var index = this.index_of(PG.RuleList[typeName], cards);
if (index >= 0)
return [typeName, index];
Expand Down

0 comments on commit cf37b1c

Please sign in to comment.