Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getBinaryTable[table_] :=
- Map[PadLeft[IntegerDigits[#, 2], 3] &, table];
- getParityTable[plusParityTable_] :=
- Table[Mod[plusParityTable[[x]], 2], {x, 1, 3}];
- getPlusListBinaryTable[tableBinary_] :=
- tableBinary[[1]] + tableBinary[[2]] + tableBinary[[3]] +
- tableBinary[[4]];
- getAdvantage[finalParityTable_] :=
- If[finalParityTable == {0, 0, 0}, "player", "computer"];
- getMatch[finalParityTable_] :=
- If[finalParityTable == {0, 0, 0}, "player", "computer"];
- getMatchTable[table_] :=
- Table[Table["|", {x, 1, table[[x]]}] // StringJoin, {x, 1, 4}];
- setTable[line_, number_] :=
- If[table[[line]] - number < 0, Print["Error"],
- table[[line]] = table[[line]] - number];
- endDetect[table_] :=
- If[table == {0, 0, 0, 0}, Print["The game is finished"]]
- getCurrentParityTable[table_] :=
- getParityTable[getPlusListBinaryTable[getBinaryTable[table]]]
- computerPlay[currentParityTable_] := Switch[currentParityTable,
- {0, 0, 1},
- For[i = 1, i <= 4, i += 4,
- If[table[[i]] > 0, table[[i]] -= 1, i -= 3]],
- {0, 1, 0},
- For[i = 1, i <= 4, i += 4,
- If[table[[i]] == 2 || table[[i]] == 3 || table[[i]] == 6 ||
- table[[i]] == 7, table[[i]] -= 2, i -= 3]],
- {1, 0, 0},
- For[i = 1, i <= 4, i += 4,
- If[table[[i]] == 4 || table[[i]] == 5 || table[[i]] == 6 ||
- table[[i]] == 7, table[[i]] -= 4, i -= 3]],
- {1, 0, 0},
- For[i = 1, i <= 4, i += 4, table[[i]];
- Which[2, table[[i]] -= 1, 4, table[[i]] -= 1, 6, table[[i]] -= 1,
- i -= 3]],
- {0, 1, 1}, For[i = 1, i <= 4, i ++, Switch[table[[i]],
- 2, table[[i]] -= 1,
- 4, table[[i]] -= 1,
- 6, table[[i]] -= 1,
- 3, table[[i]] -= 3,
- 7, table[[i]] -= 3
- ; i -= 3
- ]] ,
- {1, 0, 1}, For[i = 1, i <= 4, i += 4, Switch[table[[i]],
- 4, table[[i]] -= 3,
- 6, table[[i]] -= 3,
- 5, table[[i]] -= 5,
- 7, table[[i]] -= 5; i -= 3
- ]] ,
- {1, 1, 0}, For[i = 1, i <= 4, i += 4, Switch[table[[i]],
- 4, table[[i]] -= 2,
- 5, table[[i]] -= 2,
- 6, table[[i]] -= 6,
- 7, table[[i]] -= 6; i -= 3
- ]] ,
- {1, 1, 1}, For[i = 1, i <= 4, i += 4, Switch[table[[i]],
- 4, table[[i]] -= 1,
- 5, table[[i]] -= 3,
- 6 , table[[i]] -= 5,
- 7, table[[i]] -= 7 ; i -= 3
- ]]
- ];
- table = {};
- For[i = 1, i < 8, i += 2, AppendTo[table, RandomInteger[{0, i}]]];
- table = {1, 2, 4, 4};
- Print[table]
- binaryTable = getBinaryTable[table];
- Print[binaryTable]
- plusParityTable = getPlusListBinaryTable[binaryTable];
- Print[plusParityTable]
- finalParityTable = getParityTable[plusParityTable];
- Print[finalParityTable]
- advantage = getAdvantage[finalParityTable];
- Print[advantage]
- Dynamic[matchTable = getMatchTable[table]]
- computerPlay[finalParityTable]
- Dynamic[
- Panel[
- Panel[
- Column[
- {RadioButton[Dynamic[line], 1],
- RadioButton[Dynamic[line], 2],
- RadioButton[Dynamic[line], 3],
- RadioButton[Dynamic[line], 4],
- Text["Line" Dynamic[line]]}]
- Column[{
- InputField[Dynamic[number], Number],
- Text["Number of matches " Dynamic[number]]}]
- Button["Process",
- setTable[line, number] Print[getCurrentParityTable[table]]]]
- Panel[
- Column[{
- matchTable[[1]],
- matchTable[[2]],
- matchTable[[3]],
- matchTable[[4]]
- }, Center]
- ]
- ]
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement