• 沒有找到結果。

Worker of Game Client

The worker in our TMJ is based on the game clinet in QKMJ. However, we modify it, so it can communicate with tiles through messenger and has ability to analyze messages from tiles.

Due to two manipulating mode in mahjong game, we divide the analysis into two portions : Judge Mechanism in normal mode and in bid mode.

Judge Mechanism - Normal Mode

As mentioned in 4.1.2, there are 2 operational steps in normal mode. The first step is fixed operation, drawing a tile from wall, so if the local player do action draw (defined in 5.2) on a tile, the worker can directly determine correctly the operation the local player do. However, the player has at most 4 options in second step, so we must to design a operation-judging mechanism for the worker (Figure 5.4) to assist us to determine the operation correctly.

Notice: the assumption of Figure 5.4 is that the local player had completed the step 1 of normal mode, ie. drawing a tile from wall.

Before the local player acts on tile(s), to reset the counters is necessary and to check2 whether the local player can do OW or OCK to set the corresponding flag(s)3. These flags will

2The corresponding constraints are described in 4.1.2.

3It's meaningless to check the flag of OP K in advance, because this operation is decided based on the content of the active tile.

assist us in operation-judging period. On the other hand, by observing actions of each

operation, we discover the action of OCK is conceal (defined in 5.2) and all the one(s) of OW, OP K and discard are filp (defined in 5.2). As a result, the worker can preliminary distinguish whether the local player want to do OCK.

When the local player do action conceal on a tile with state in-hand (defined in 5.2), the worker will receive a corresponding response message form the tile. Then, it increases counter if the flag of OCK is set and the content of the concealed tile is valid for OCK (shown in Figure 5.4 as the conditional expression : " Correspond with OCK? " ). When the number of counter equals 4, OCK is the operation the local player do, and the operation-judging work finish.

However, when the local player do action flip on a tile with state in-hand, the worker cannot distinguish what the local player want to do only by a flip-reporting message.

Therefore, some conditionals are applied to assist us to determine which operation is correct.

We discover the number of manipulated tiles of the possible operation OW is different than OP K or Discard. The number of manipulated tiles of operation OW must larger than 2, but the one of the last two is 1. It means that the worker not only receives the flip-reporting message one time if the local player want to do OW. As a result, the worker prior considers whether the flag of OW is set (shown in Figure 5.4 as the conditional expression :" Correspond with OW? "

).

If the flag of OW is not set, then the operation the local player want to do only remain 2 possibilities: OP Kor Discard. Therefore, the worker considers the content of this flip tile, if the tile meets the constraints of OP K: the content of the tile is the same as the one of the exposed pong meld (shown in Figure 5.4 as the conditional expression : " Correspond with OP K? " ), the worker can get a conclusion that the OP K is the operation the local player do, and the operation-judging work finish.

Figure 5.4: Judge Mechanism - Normal Mode

On the other hand, if the flag of OW is set, there are still 3 possibilities of the operation.

Nevertheless, another counter be applied to record the number of flip-reporting message(s), if the worker just receive a message now, timer will be applied to assist judging operation: when the worker receives another flip-reporting message in the limited period, it can determine the OW is the operation the local player do, and the operation-judging work finish. However, if the worker receive the Timeout-reporting message, it means the OW is not the one, so the

approach for not setting flag of OW will be applied to cope this situation.

Judge Mechanism - Bid Mode

We analyzed the bid mode in 4.1.2, so we know that the bid mode not always be triggered every time. Therefore, the worker have to judge whether the local player wants to bid the discarded tile, and a timer is applied to assist the worker to understand the intention of the local player. If worker receives any flip-reporting message in the limited period, it will be accounted

Figure 5.5: Judge Mechanism - Bid Mode : Basic Processing Logic Schema

that the local player intents to bid the discarded tile, and vice versa. Then, after the worker accounts the local player's intention to bid the discarded tile, the operation-judging mechanism in bid mode is triggered.

Figure 5.5 shows the processing logic of the operation-judging mechanism after it receives a flip-reporting message. First, it checkes whether the message is valid for one of the bidding operations the local player allowed to do. (We will discuss what is valid later) The message will be ignored if it's invalid. But, if it's valid, the worker subsequently checkes whether the valid messages collected so far ( in this judging-operation period) meet the constraints of a specific bidding operation. If these messages meet the constraints, the worker can get a

conclusion that this specific bidding operation is that the local player want to execute, then the operation-judging mechanism terminated. However, if these messages don't meet the

constraints, this operation-judging mechanism still works until it receives enough constraint-meeting messages.

Before we discuss which message is valid for operation-judging process, we list TMJ notations used in Table 5.1.

Contents of a active tile, number of active tiles, and timer are the bases applied to judge

Table 5.1: TMJ Notation Notation Definition

Ti Single tile STi Suit of Ti V Ti Value of Ti

Γact Set of act tiles in this period

∆T A limited time

∆t The time between detecting active tiles Table 5.2: Valid Messages for Judge Mechanism in Bid Mode

ID Schema Conditional Handling

whether the message is valid. A total of the valid messages is five, and each of them has corresponding conditional listed in Table 5.2.

Among these valid messages, the judging basis of V M 4 is timeout, while the ones of others are contents or number of active tiles. There are 2 situations that we apply timer to assist judging operation. First, the flag of OW is set and the flag of OP or OKor OS is set.

Second, Both the flag of OP and OK are set.

Like judge mechanism in normal mode, we check whether the local player can do

operation, OS, OP, OKand OW, then setting the corresponding flag(s). We use a circle symbol including some of operations (as illustrated in Figure 5.6 ) to represent a kind of situation that flags of these operations are set.

Figure 5.6 shows all the situations of judging procedure of the operation-judging mechanism in bid mode. At beginning, there must exist a kind of situations, all possible

situations at beginning are listed on the left of Figure 5.6a. If a valid message appears, the worker executes the corresponding handling also listed in Table 5.2. With these handling, the quantity of possible operations decreases gradually. However, even if one possible operation is remained, the operation-judging mechanism keeps working until receiving enough valid messages to meet the corresponding constraints.

The scenario of first valid message adopted by the worker is illustrated in Figure 5.6a.

Obviously, for most of situations on the left, the valid message reduces the possible operations.

However, the quantity of valid message is insufficient, so operation-judging mechanism continues to work.

Similarly, the scenario of second, third, and forth valid message adopted by the worker are illustrated in Figure 5.6b, Figure 5.6c, and Figure 5.6d. We paint the circle symbol with

colorful background to represent the worker ends judging operation, and combine these scenarios into Figure 5.6e.

相關文件