I am participating in the nuggets Community game creative submission Contest. For details, please see: Game Creative Submission Contest

preface

Gobang, also known as gobang, is an interesting and puzzle board game that has been played in dozens of countries around the world. The World gobang Championship has been held for several times, and entered the World Intellectual Sports Olympics competition, its influence is growing. Five-piece chess is easy to learn, but fun. The next game of chess is not much time, after dinner “kill a plate”, the development of intelligence, diligent use of the brain, regulating feelings, is conducive to the development of intelligence, home necessary.

Code snippet –

The line is gone ε(┬┬﹏┬┬)3

The rules of the game

The traditional backgammon has roughly the same equipment as go. The pieces are black and white, the board is 15×15, and the pieces are placed at the intersections of the board lines. Two games, each with one color, take turns next son, first horizontal, vertical or diagonal line of 5 or more than 5 pieces of the same color into an uninterrupted row to win (in the formal game black can only be linked into 5. A row of 6-9 counts as a ban, and black also has bans of 33 and 44. Black’s forbidden hand is lost. White has no restrictions).

layout

Drawing board

var chressBord = []; Var I = 0; i < 15; i++){ chressBord[i] = []; for(var j = 0; j < 15; j++){ chressBord[i][j] = 0; Var drawboard = function() {for(var I = 0; i < 15; i++){ context.moveTo(15 + i * 30 , 15); context.lineTo(15 + i * 30 , 435); context.stroke(); context.moveTo(15 , 15 + i * 30); context.lineTo(435 , 15 + i * 30); context.stroke(); }}Copy the code

Painting pieces

Var oneStep = function(I,j,me) {context.beginPath(); context.arc(15 + i * 30, 15 + j * 30, 13, 0, 2 * Math.PI); / / circle context. ClosePath (); / / the gradient var gradient = context. CreateRadialGradient (15 + I * 30 + 2, 15 + j * 30-2, 13, 15 + I * 30 + 2, 15 + j * 30 - 2, 0); if(me){ gradient.addColorStop(0,'#0a0a0a'); gradient.addColorStop(1,'#636766'); Else {gradient.addColorStop(0,'#d1d1d1'); gradient.addColorStop(1,'#f9f9f9'); } context.fillstyle = gradient; context.fill(); }Copy the code
Var myWin = []; var computerWin = []; Var wins = []; for(var i = 0; i < 15; i++){ wins[i] = []; for(var j = 0; j < 15; j++){ wins[i][j] = []; } } var count = 0; For (var I = 0; i < 15; i++){ for(var j = 0; j < 11; j++){ for(var k = 0; k < 5; k++){ wins[i][j+k][count] = true; } count++; }} for(var I = 0; i < 15; i++){ for(var j = 0; j < 11; j++){ for(var k = 0; k < 5; k++){ wins[j+k][i][count] = true; } count++; }} for(var I = 0; i < 11; i++){ for(var j = 0; j < 11; j++){ for(var k = 0; k < 5; k++){ wins[i+k][j+k][count] = true; } count++; }} for(var I = 0; i < 11; i++){ for(var j = 14; j > 3; j--){ for(var k = 0; k < 5; k++){ wins[i+k][j-k][count] = true; } count++; } } // debugger; for(var i = 0; i < count; i++){ myWin[i] = 0; _myWin[i] = 0; computerWin[i] = 0; _compWin[i] = 0; }Copy the code

back

Backbtn. onclick = function(e) {if (! backAble) { return; } over = false; me = true; // resulttxt. innerHTML = 'o(╯□╰)o '; / / cancel the undo function available returnbtn. ClassName = returnbtn. ClassName. Replace (new RegExp (' (\ \ s | ^) unable (\ \ s | $) '), ' '); ChressBord [_nowi][_nowj] = 0; MinusStep (_nowi, _nowj); minusStep(_nowi, _nowj); Var k = 0; k < count; K++) {/ / will probably win is minus 1 if (wins [_nowi] [_nowj] [k]) {myWin [k] -; computerWin[k] = _compWin[k]; ChressBord [_compi][_compj] = 0; MinusStep (_compi, _compj); Var k = 0; k < count; K++) {/ / will probably win is minus 1 if (wins [_compi] [_compj] [k]) {computerWin [k] -; myWin[k] = _myWin[i]; }} resulttxt. innerHTML = '-- Backgammon --'; returnAble = true; backAble = false; }; Onclick = function(e) {if (! returnAble) { return; } chressBord[_nowi][_nowj] = 1; OneStep (_nowi, _nowj, me); for (var k = 0; k < count; k++) { if (wins[_nowi][_nowj][k]) { myWin[k]++; _compWin[k] = computerWin[k]; computerWin[k] = 6; } if (myWin[k] == 5) {resulttXt. innerHTML = 'Congratulations, you have won! '; over = true; ChressBord [_compi][_compj] = 2; OneStep (_compi, _compj, false); for (var k = 0; k < count; K++) {/ / will probably win is minus 1 if (wins [_compi] [_compj] [k]) {computerWin [k] + +; _myWin[k] = myWin[k]; myWin[k] = 6; } if (computerWin[k] == 5) {resulttxt. innerHTML = 'o(╯□╰)o, continue to win! '; over = true; } } returnbtn.className += ' ' + 'unable'; returnAble = false; backAble = true; };Copy the code

When playing backgammon, the most taboo is complacent. Sometimes clearly looking at themselves as long as the next step can win, but there is no counterattack in the opponent’s successive moves, just one step lost the whole game. The most helpless is clearly see others to, also can predict the opponent next step will be next where, but everything is in vain, can helplessly look at the opponent step by step will be forced to their own desperate. Life is not so? Sometimes know is a conspiracy, but always helpless into it unable to extricate themselves.

conclusion

We are all a chess piece in the hands of time, there is no time to see what will happen after the fall, when the surrounding dense fall full of chess, only to know the meaning of their own. Do you know that everyone is interconnected and indispensable? It is impossible to say that one piece goes this way and the other goes that way without any connection. When playing chess, pay attention to the overall situation, can not be impatient, first to see the chess situation, and then slowly consider where the next step is appropriate, when one day can be calm and play a game of chess, even if you can not change anything, you will find that the world and thought before some different.