1643571600
Argitalpen honetan, zer den Block Reward Crypto-n, Bitcoin Block Reward, mugak eta bere erronkak eztabaidatuko ditugu.
Zailtasuna Proof-of-Work meatzaritzaren alderdi garrantzitsuenetako bat da. Sareko hashrate erabiliz eratorria da eta meatzariek bloke enkriptatu bat baliozkotzeko gai diren abiadura zehazten du. Bitcoin meatzaritzaren testuinguruan, zailtasuna 2016 bloke bakoitzean doitzen da eta 10 minutuko batez besteko bloke-denbora mantentzea du helburu.
Sari honek honako hau bermatu nahi du:
Hortik dator bloke sarien garrantzia blockchain sareen funtzionamendua mantentzeko eta mantentzeko. Baina zeregin sinple hau ez da dirudien bezain erraza. Bloke-saria txanponak kontrolik gabe sortzea kontrolatzen duen sistema bati egokitu behar zaio inflazioa kaltetu ez dadin. Horren guztiaren erdian, berebiziko garrantzia duten hainbat alderdi daude.
Hori dela eta, artikulu hau modu errazean azalduko da blokeen sariak nola kalkulatzen diren trazu zabalean eta kriptomonetan duen garrantzia eta eragina.
Bitcoin blokearen saria bi osagaik osatzen dute: sortu berri diren txanponak eta transakzio-kuotak. Sortu berri diren txanponen kopuruak bitcoins berrien hornikuntza adierazten du eta 4 urtean behin gertatzen den erdira murrizteko ekitaldi batek gobernatzen du. Erdira murrizteko gertaera honek sortu berri diren bitcoins hornidura erdira murrizten du eta hornidura jaulkipena estutu nahi du 21 milioi bitcoin guztiak atera arte.
Egungo bitcoin bloke-saria 6.25 berriki sortutako txanponez osatuta dago transakzio-kuotez gain. Transakzio-kuotei dagokienez, hainbat faktoreren ondorioz alda daitezke. Hala ere, transakzio-kuotak aldatzea eragiten duten arrazoietan sakondu aurretik, garrantzitsua da transakzio bat hasten denean zer gertatzen den ulertzea.
Erabiltzaile batek transakzio bat hasten duen bakoitzean, transakzioa sarera igortzen da eta, ondoren, memoria multzoan jartzen da (mempool izenez ere ezaguna; transakzioen itxaron-eremua) bloke batean sartu aurretik. Meatzariek, ondoren, mempool-eko transakzio guztiak aztertuko dituzte eta transakzio-kuotaren arabera iragaziko dituzte eta ahalik eta gehien sartzea aukeratuko dute, kuota handiagoak dituzten transakzioak lehenesten dituzten bitartean.
Bloke baten sariak bere kalkulurako kontuan hartu beharreko elementu edo alderdi batzuk biltzen ditu. Alderdi horien artean aipa ditzakegu:
Bloke-sari bat kalkulatzea lehenengo erantzunez gertatzen da: Zenbat txanpon sortuko dira guztiz bloke-katean?. Bitcoin-en kasuan, txanpon guztiak 21 milioi BTCra iritsiko dira. Ez dirudi oso kopuru handia denik, baina egia da hala dela. Erabil daitekeen BTC gutxieneko kopuruak 8 hamartar dituela kontuan hartzen badugu, erabiltzeko aukera hazten da.
Baina ziur asko galdetuko dute: Zergatik da garrantzitsua jakitea jaulki beharreko kripto-moneta kopurua bloke bakoitzeko saria kalkulatzeko? Erantzuna erraza da: sari banaketak egin nahi baditugu, jakin behar dugu zenbat jaulkiko dugun eta nola banatuko dugun gai hori.
Kontuan izan kriptomoneten helburua sistema guztiz deszentralizatua izatea dela. Hori ez bakarrik bere kudeaketan eta kontrolan baita ekonomikoki ere. Alferrik da txanponak pertsona gutxi batzuen esku dauden kriptografia-moneta izatea. Horrek bere existentziak zentzua galduko luke. Hori dela eta, hobe da sortutako kripto-monetak gehienez zatitzea eta zabaltzea. Hori lortzeko modu bat sariak banatzea da hedapen handiena bilatuz, jende gehiagok onura atera dezan. Mekanismo honek erabilera zabaldu eta jende gutxik ekosistema kontrolatzea saihestu nahi du, zentralizazioa saihestuz.
Une honetan, blockchain-ak zenbat txanpon aterako dituen jakitea oso garrantzitsua da, existentzia mugatua duen objektu bat balio handiko objektua baita. Orain ulertu dezakezu bildumazale batek hainbeste diru ordain dezakeen existentzia mugatuko objektuengatik. Eta ziur aski ulertu dezakezu zergatik iristen den Bitcoin balio-maila horietara.
Bloke-sari baten balioa ezartzeko bigarren puntu garrantzitsua jakitea da: Zenbat denbora iraungo du emisio osoa? . Une honetan bezain erraza da eta Bitcoin-en adibidea hartuko dugu. 10 minuturo bloke bat jaulkitzen badugu eta urtebete baino gutxiagoan 21 milioi txanpon igorri nahi baditugu, bloke bakoitzeko saria oso altua izan behar da (~ 400 BTC bloke bakoitzeko). Hala ere, hori oso inflazio altua da eta, edozein kasutan, kontrakoa. Gogoratu kriptografia-moneta eskaintza handiagoarekin horren balioa murrizten dela eta, nolanahi ere, kontrako efektua nahi dugula. Bitcoin atzean dagoen ideia ordainketa sistema global seguru eta baliotsua sortzea da, eta horretarako inflazioa kontrolatu behar da.
Horregatik hartzen da kontuan kriptomoneta jaulkitzeak iraungo duen denbora. Bitcoin-en kasuan, bere jaulkipena 2144 urtean amaituko da, meatzaritza hasi eta 135 urte geroago. Modu honetan, BTCn txanpon berrien sorrera kontrolatzen eta zuzentzen da bere balioa handitzeko eskaintza eta eskariaren Legearen baitan.
Badira beste kasu batzuk, adibidez, txanponen jaulkipena infinitua den. Ethereum eta Monero bezalako kasuak oso ezagunak dira bi. Baina hasieran sistema hauek ere badute, printzipioz, aldi baterako kontrolatutako emisioa, gero infinitura hedatzen dena sari txikiagoekin.
Gainerako faseen multzokatzea hemen gertatzen da, eta sariaren kalkulua blockchain softwarearen iturburu-kodean dago. Une honetan, dena elkartzen da eta softwareak nodo guztiei adierazten die une zehatz horretan bloke-sariaren benetako balioa. Bitcoin-en kasuan, sariaren balioa kalkulatzen duen programazioa bi zatitan banatzen da:
Bloke sariak ezin du inolako baliorik izan. Hau da, sari horren balioa kriptografia-moneta ekonomia modu osasuntsu batean abiatzea eta mantentzea ahalbidetzen duena izango delako.
Irakurri gehiago: Zer da Bitcoin Halving | Nola funtzionatzen du eta zergatik du garrantzia?
Lehen aipatu dugun bezala, bloke baten sariaren garrantzia txanpon berriak sortzea da. Izan ere, blockchain baten barruan txanpon berriak sortzeko dagoen modu bakarra da. Gainera, haren sorrerak eta kontrolak sistema ekonomiko deszentralizatua sortzea ahalbidetzen du. Meatzariek dirua inbertitzen duten bat, bitcoinak meatzean konputazio ahalmen gehiago gehitzeko. Euren inbertsio monetario eta teknologikoarekin, meatzariek sarea deszentralizatzen eta ziurtatzen dute erasoak saihesteko. Eta, aldi berean, txanponak sortzen dituzte, besteek beren trukeetarako erabil ditzaketenak.
Bitcoin blockchain-eko bloke bakoitzak 1 MBko datu bakarrik eduki ditzake eta horrek meatzariek sar ditzaketen transakzio kopurua mugatzen dute.
Horrek erabiltzaileen arteko lehia sentsazioa sortzen du.
Zenbat eta handiagoa izan transakzioarekin lotutako kuotak, orduan eta azkarrago prozesatu egingo da transakzioa. Sarea moteltzea eragiten duten zenbait abiarazle daude, erabiltzaileak transakzio-kuotak kezkaz handitzera behartzen dituzte transakzioaren prozesamendua azkartzeko.
Eragile horietako batzuk hauek dira:
Lehen esan bezala, meatzaritza-zailtasuna 2016ko bloke guztietan doitzen da eta aurreko 2016ko blokeen batez besteko sareko hashrata erabiltzen du hurrengo 2016ko blokeetan 10 minutuko batez besteko bloke-denbora mantentzeko beharrezkoa den zailtasuna kalkulatzeko. Hala ere, zuzeneko sarearen hashrate-a zailtasunak doitzeko erabiltzen den sarearen hashratea baino askoz ere handiagoa edo txikiagoa bada, sarearen errendimenduari eragingo zaio, eta 10 minutuko batez besteko bloke-denboratik desbideratuko da. Horrek transakzioak prozesatzeko abiaduran eragiten du eta transakzio-kuota txikiagoak edo handiagoak eragingo ditu, sareak errendimendu gutxi edo gehiegi egiten duenaren arabera.
Funtsean, zailtasunak doitzeko erabiltzen den sarearen hashratearen eta sarearen hashratearen arteko aldea positiboa bada, zailtasunak aurreikusitakoa baino hashrate handiagoa dago. Honi esker, blokeak 10 minutuko batez besteko bloke-denbora baino azkarrago berresten dira eta erabiltzaileek ez dute lehiatu behar transakzioa bloke batean sartzeko.
Era berean, zailtasunak doitzeko erabiltzen den sarearen hashratearen eta sarearen hashratearen arteko aldea negatiboa bada, zailtasunak aurreikusitakoa baino hashrate txikiagoa izango da eta, beraz, blokeak zuzendutako 10 minutuko batez besteko bloke-denbora baino motelago berresten dira. Horrek erabiltzaileen arteko lehian bizkorra eragiten du transakzio-kuotak handitzen baitituzte transakzioa bloke batean sartzen dela ziurtatzeko.
Beheko grafikoan ΔHashrate (%) (eskuinean-y) (zuzeneko sarearen hashratearen eta zailtasunak doitzeko erabiltzen den sarearen hashratearen arteko aldea) eta transakzioen batez besteko kuota (ezkerrean-y) arteko korrelazioa erakusten da . Erlazio honen korrelazio-koefizientea – 0,5 da eta korrelazio negatibo samarra adierazten du.
Bitcoin bloke-sarian sortu berri diren txanponen zatia oso aurreikusgarria den arren, transakzio-kuoten zatia nahiko nabarmen aldatzen da eta oso ezustekoa izan daiteke.
Hashratearen jaitsiera nabarmenaren ondorioz blokeen batez besteko denbora % 30 handitu zen adibide oso ona 2021eko apirilaren amaieran Barne Mongolian bitcoin meatzaritza debekatu zelako gertatutako gertakaria da. Gertaera honek bitcoin hashratearen% 10 jaitsi eta batez besteko bitcoin blokearen denbora 14 minutura igo zen. Hori dela eta, erabiltzaileek transakzio-kuotak batez beste % 30 handitu behar izan zituzten beren transakzioak garaiz prozesatzen zirela ziurtatzeko.
Hona hemen zer gerta daitekeen Bitcoin hornidura agortu ondoren
2021eko abenduaren 13an, Bitcoin kriptografia-moneta bere hornidura maximoaren ehuneko 90era iritsi zen. Blockchain.com-ek egindako ikerketa batek agerian utzi zuen 21 milioi Bitcoin-en hornidura osotik, 18,89 milioi dagoeneko atera direla eta merkatuan zirkulatzen ari direla. Mugarria 2009ko urtarrilaren 9an lehen blokea, 50 Bitcoinz osatua, atera zenetik ia 12 urtera dator.
Hasi gabekoentzat, Bitcoin hornidura mugatua duen kripto-moneta bakanetako bat da. Satoshi Nakamoto Bitcoin asmatzaileak Bitcoin-en kopurua 21 milioitan mugatu zuen, kriptografia-moneta urri bihurtzeko eta hornikuntza mugagabe batetik sor zitekeen inflazioa kontrolatzeko. Bitcoin bere sarean gertatzen diren transakzio blokeak egiaztatzeko eta baliozkotzeko puzzle matematikoak ebazten dituzten meatzariek "meatzen" dute. Bitcoins berriak zirkulazioan gehitzeko prozesu bat da. Transakzio multzo bat arrakastaz egin ondoren, meatzariari Bitcoins bloke bat ematen zaio.
Bitcoin-en 21 milioi mugaren ondorioak aztertu aurretik, interesgarria izan daiteke inoiz kopuru horretara iritsiko den aztertzea.
Hasiberria bazara. Beheko artikulua erabilgarria izango zaizula uste dut ☞ Kriptomonetan inbertitu aurretik jakin beharko zenukeena - Hasiberrientzako
Kontuan izan behar da lau urtean behin Bitcoin meatzaritzaren saria erdira murrizten dela. Beraz, Nakamotok 2008an Bitcoin sortu zuenean, transakzio bloke bat berresteko saria 50 Bitcoins zen. 2012an, 25 bitcoinera erdira jaitsi zen, eta 2016an 12,5era jaitsi zen. 2020ko maiatzean, meatzariek 6,25 Bitcoin irabazten zuten bloke berri bakoitzeko, eta 2024 amaierarako espero da meatzariek 1,56 Bitcoin bakarrik irabaztea. transakzio bloke bat egiaztatzeko. Prozesu honi erdibitzea deitzen zaio eta azken Bitcoina atera arte jarraituko du.
Badirudi munduko kriptografia-moneta ezagunena agortzetik gertu dagoela, baina Bitcoin-en erdira murrizteko programak aurreikusten du gainerako ehuneko 10eko hornidura 2140ko otsailera arte iraungo duela, blockchain.com-en arabera.
Gainera, Bitcoins kopuru osoa ez dago eskuragarri merkatu irekian banatzeko. Chainalysis-ek, analisi-enpresa batek, agerian utzi zuen 3,7 milioi Bitcoin inguru galdu direla dagoeneko hainbat arrazoirengatik, besteak beste, norberaren gako pribaturako sarbidea galtzea, heriotza eta abar.
Bitcoin-en hornidura mugara hurbiltzen ari denez, hona hemen inbertitzaileengan eta blockchain sarean izango dituen ondorio nabarmen batzuk.
Zirkulazioan 21 milioi hornikuntzara iritsi ondoren, Bitcoin urriagoa izango da eta meatzariak transakzio-kuoten menpe egongo dira, bloke-sarien ordez. Meatzariak bloke-kate hauetan gertatzen diren transakzioetatik gehiago irabazten hasiko dira meatzaritzatik bertatik baino.
Aipatzekoa da Bitcoin ez dela kriptografia-moneta soilik, transakzioak banatutako liburu-esparru batean prozesatzen dituen blockchain sare bat baizik. Beraz, teknologiak askoz erabilera kasu gehiago ditu kriptografia-aktibo bat izatea baino.
Bitcoin teknologia aldatzeko etorkizuneko ahaleginak gorabehera, adituek etorkizunari buruz espekulatzen jarraitzen dute gehienezko mugara iritsitakoan. Analista batzuek diote teknologia berriek meatzaritzaren kostua murrizten lagunduko dutela (Bitcoin meatzaritzak elektrizitatea modu intentsiboan erabiltzen duten potentzia handiko ordenagailuak behar ditu), eta horrek azkenean meatzarientzat irabazi gehiago ekarriko ditu.
Beste batzuek iradokitzen dute Bitcoin plataformak balio oso handiko transakzio handietarako soilik erabiliko direla, eta horrek diru-sarrera nahikoak eskainiko ditu interesdunak pozik mantentzeko.
Espero dut mezu honek lagunduko dizula. Ez ahaztu atsegin bat uztea, iruzkintzea eta besteekin partekatzea. Eskerrik asko!
1675381680
Do you want to make a Simple Tic-Tac-Toe game using JavaScript?
In this article you will learn how to create tic tac toe game using html css and javascript. If you are a beginner in JavaScript then Tic Tac Toe Game is perfect for you. This simple javascript game will help you improve your knowledge of javascript.
Earlier I shared another Simple Tic-Tac-Toe JavaScript game for beginners. So I made this design in a very advanced way. Here basically we will play with the computer that is we will play with the computer.
To create this tic-tac-toe javascript first I created the basic structure by html. Then I designed it with css and finally activated this project (tic tac toe javascript code against computer) with javascript.
JavaScript Tic Tac Toe is a simple game where two players take turns marking a grid of 3×3 squares, typically using X and O symbols. JavaScript is a programming language that can be used to create interactive websites and games, such as a Tic Tac Toe game.
A JavaScript implementation of Tic Tac Toe would involve creating a grid of squares using HTML and CSS, and then using JavaScript to handle the logic of the game, including determining the winner and allowing players to take turns.
As you can see above this is an advanced Tic Tac Toe game that I made with javascript. Like a normal JavaScript Tic Tac Toe game, there are 9 cells and two symbols.
Here I have defined symbol “0” for user and “X” for computer. But you can change it if you want. When you click in any one of those 9 cells, another cell will automatically be filled by the computer.
Besides, I have added different types of color FF in the project (tic tac toe javascript code against computer) to make this design more modern.
Now if you want to build it then you can follow the tutorial below. I have explained the complete codes step by step keeping the beginners in mind.
Hope you know the rules of this game. It is a simple javascript game where two players take turns marking the spaces in a 3×3 grid with X’s and O’s, with the goal of getting three of their marks in a row, either horizontally, vertically, or diagonally. The player who succeeds in placing three of their marks in a row is the winner.
First I created a basic structure of this project using the following HTML and CSS codes. Besides, I have added a heading here mainly to enhance the beauty. This heading is created by H1 tag in HTML.
<div class="container">
<h1>Tic-Tac-Toe</h1>
</div>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Arial, Helvetica, sans-serif;
}
.container {
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: #eee;
}
h1 {
font-size: 4rem;
margin-bottom: 0.5em;
}
Now create a small area for this tic tac toe javascript. Within this box are nine smaller boxes into which players can input their symbols. Also we designed this area by some css.
<div class="play-area">
</div>
.play-area {
display: grid;
box-shadow: 0 0 20px rgba(0,139,253,0.25);
grid-template-columns: auto auto auto;
background-color: #fff;
padding: 20px;
}
Now another heading we need to create is within this project(How to Build Tic Tac Toe with JavaScript, HTML and CSS). This heading is mainly for showing results.
Although this heading is currently not visible to us because there is no information in the heading. We will add this information via javascript. Results will be available automatically after Tic Tac Toe game is over.
<h2 id="winner"></h2>
h2 {
margin-top: 1em;
font-size: 2rem;
margin-bottom: 0.5em;
}
Now we have to create a button in this simple Tic-Tac-Toe game. This button will basically work as a reset button. When you click on this button, the game will restart from a new state.
<button onclick="reset_board()">RESET</button>
button {
outline: none;
background: rgb(8, 88, 208);
padding: 12px 40px;
font-size: 1rem;
font-weight: bold;
color: #fff;
border: none;
transition: all 0.2s ease-in-out;
}
button:hover {
cursor: pointer;
background: green;
color: white;
}
Above we have designed this project(How to create a tic tac toe grid in JavaScript?). Now it’s time to make it work using JavaScript. We have used quite a bit of JavaScript code to make this game work. But don’t worry I will tell you all the codes step by step.
const player = "O";
const computer = "X";
let board_full = false;
let play_board = ["", "", "", "", "", "", "", "", ""];
const board_container = document.querySelector(".play-area");
const winner_statement = document.getElementById("winner");
With these variables, you’ve defined the player and computer as “O” and “X” respectively, and created an empty board to play on. The board_full
variable will be used to check if the board is full and the game is over, and the play_board
array will hold the state of the game.
The board_container
variable is used to select the element on the page where the Tic Tac Toe board will be rendered, and the winner_statement
variable is used to select the element where the winner statement will be displayed.
check_board_complete = () => {
let flag = true;
play_board.forEach(element => {
if (element != player && element != computer) {
flag = false;
}
});
board_full = flag;
};
The function is using the forEach()
method to iterate over the play_board
array, and it checks if each element is not equal to the player or computer. If any element is not equal to the player or computer, it sets the flag variable to false and breaks out of the loop.
If the loop completes and the flag variable is still true, it means that all the elements are equal to the player or computer, and the board is full. Then the board_full
variable is updated to reflect that the board is full.
You can use this function at the end of the player’s turn and computer’s turn, to check if the board is full and the game is over.
const check_line = (a, b, c) => {
return (
play_board[a] == play_board[b] &&
play_board[b] == play_board[c] &&
(play_board[a] == player || play_board[a] == computer)
);
};
The function takes in 3 arguments, a
, b
, c
, which represent the indices of the 3 cells on the board that need to be checked for a winning line.
The function uses the ternary operator to check if the values at the indices a
, b
, c
in the play_board
array are the same and not empty. If the values are the same and not empty, the function returns true, otherwise it returns false.
You can use this function in a larger function that checks for all the possible winning combinations on the board.
const check_match = () => {
for (i = 0; i < 9; i += 3) {
if (check_line(i, i + 1, i + 2)) {
document.querySelector(`#block_${i}`).classList.add("win");
document.querySelector(`#block_${i + 1}`).classList.add("win");
document.querySelector(`#block_${i + 2}`).classList.add("win");
return play_board[i];
}
}
for (i = 0; i < 3; i++) {
if (check_line(i, i + 3, i + 6)) {
document.querySelector(`#block_${i}`).classList.add("win");
document.querySelector(`#block_${i + 3}`).classList.add("win");
document.querySelector(`#block_${i + 6}`).classList.add("win");
return play_board[i];
}
}
if (check_line(0, 4, 8)) {
document.querySelector("#block_0").classList.add("win");
document.querySelector("#block_4").classList.add("win");
document.querySelector("#block_8").classList.add("win");
return play_board[0];
}
if (check_line(2, 4, 6)) {
document.querySelector("#block_2").classList.add("win");
document.querySelector("#block_4").classList.add("win");
document.querySelector("#block_6").classList.add("win");
return play_board[2];
}
return "";
};
The check_match()
function uses two for loops to check for all the possible winning combinations on the board, both horizontally and vertically. It also includes two if statements to check for the two diagonal winning combinations.
The function uses the check_line
function you created earlier to check if a line is a winning line. If a winning line is found, the function highlights the winning cells by adding the “win” class to them. This class can be used in your CSS to change the appearance of the winning cells, for example by adding a different background color.
The function also returns the value of the first cell in the winning line, which should be either “X” or “O” depending on who won the game.
You can use this function in another function that checks for a win or a draw and updates the UI accordingly.
const check_for_winner = () => {
let res = check_match()
if (res == player) {
winner.innerText = "Winner is player!!";
winner.classList.add("playerWin");
board_full = true
} else if (res == computer) {
winner.innerText = "Winner is computer";
winner.classList.add("computerWin");
board_full = true
} else if (board_full) {
winner.innerText = "Draw!";
winner.classList.add("draw");
}
};
This code looks like it’s checking for a winner in a javascript Tic Tac Toe game. The check_line
function takes in 3 indices of the play_board array and checks if the values at those indices are equal to each other and if they are equal to either the player or computer.
The check_match
function uses the check_line
function to check for a winner across the rows, columns, and diagonals of the Tic Tac Toe board. If a winning line is found, the check_match
function adds a “win” class to the corresponding HTML elements of the Tic Tac Toe board and returns the winning player.
The check_for_winner
function calls the check_match
function and checks the returned value. If the returned value is the player, it sets the winner statement to “Winner is player!!” and adds playerWin class.
const render_board = () => {
board_container.innerHTML = ""
play_board.forEach((e, i) => {
board_container.innerHTML += `<div id="block_${i}" class="block" onclick="addPlayerMove(${i})">${play_board[i]}</div>`
if (e == player || e == computer) {
document.querySelector(`#block_${i}`).classList.add("occupied");
}
});
};
The render_board()
function creates a grid of divs in the HTML, each one representing a cell in the Tic-Tac-Toe board. The addPlayerMove()
function allows the player to make a move by clicking on a cell in the grid.
The check_board_complete()
function checks if the board is full and the check_for_winner()
function checks for a winner or draw. It also uses the check_match()
function to check if any winning combination is formed.
const game_loop = () => {
render_board();
check_board_complete();
check_for_winner();
}
The game_loop
function combines all of these functions together to create the game loop that updates the game state and renders the game board to the user.
It calls the render_board
function to render the current state of the game board to the user, check_board_complete
to check if the board is full and check_for_winner
which checks if there is a winner or a draw, and updates the UI accordingly.
const addPlayerMove = e => {
if (!board_full && play_board[e] == "") {
play_board[e] = player;
game_loop();
addComputerMove();
}
};
The above code defines a Tic Tac Toe game in JavaScript that uses HTML and CSS for the game board and styling. The game’s state is maintained in the play_board
array, and the game_loop
function updates the state of the game, renders the board, and checks for a winner.
The addPlayerMove
function allows players to make a move by clicking on a block on the board, and the addComputerMove
function allows the computer to make a move. The check_match
, check_for_winner
, render_board
functions are also defined and used in the game loop to check for a winner or a draw, render the board and check if the game is complete.
const addComputerMove = () => {
if (!board_full) {
do {
selected = Math.floor(Math.random() * 9);
} while (play_board[selected] != "");
play_board[selected] = computer;
game_loop();
}
};
Great! Your code is now complete and should be able to run a game of javascript Tic-Tac-Toe between a player and the computer. The player can make moves by clicking on the blocks on the game board, and the computer will randomly select an available space to make its move. The code also checks for a winner or a draw after each move, and updates the game board and the winner statement accordingly.
const reset_board = () => {
play_board = ["", "", "", "", "", "", "", "", ""];
board_full = false;
winner.classList.remove("playerWin");
winner.classList.remove("computerWin");
winner.classList.remove("draw");
winner.innerText = "";
render_board();
};
This code defines a function called “reset_board” that sets the play_board array back to an empty array, sets the board_full variable to false, removes any classes related to winning or drawing from the winner element, sets the inner text of the winner element to an empty string, and then calls the render_board function to update the display. This function is likely intended to be used as a way to clear the game board and start a new game.
//initial render
render_board();
That’s it, you have created a complete Tic-Tac-Toe game using JavaScript. To start the game, the player can click on any of the empty blocks on the board and the computer will automatically make its move.
The game checks for a winner or a draw after each move and updates the board accordingly. The game can also be reset by calling the reset_board()
function.
Above we enabled Tic-tac-toe in JavaScript by JavaScript. Now we need to design it with some more CSS. We know there are 9 small boxes in this game that are currently too small for us to see. So a fixed size must be defined for each box.
.block {
display: flex;
width: 100px;
height: 100px;
align-items: center;
justify-content: center;
font-size: 3rem;
font-weight: bold;
border: 3px solid black;
transition: background 0.2s ease-in-out;
}
.block:hover {
cursor: pointer;
background: #0ff30f;
}
.occupied:hover {
background: #ff3a3a;
}
.win {
background: #0ff30f;
}
.win:hover {
background: #0ff30f;
}
As we can see in the above image there are 9 boxes created. But we want to hide some borders here. We will use the following CSS to hide those borders.
#block_0,
#block_1,
#block_2 {
border-top: none;
}
#block_0,
#block_3,
#block_6 {
border-left: none;
}
#block_6,
#block_7,
#block_8 {
border-bottom: none;
}
#block_2,
#block_5,
#block_8 {
border-right: none;
}
.playerWin {
color: green;
}
.computerWin {
color: red;
}
.draw {
color: orangered;
}
We’ll make this project(Create a Tic-Tac-Toe with HTML and JavaScript) responsive using a small amount of our own code. Here for Responsive only headings have been resized or reduced.
@media only screen and (max-width: 600px) {
h1 {
font-size: 3rem;
margin-bottom: 0.5em;
}
h2 {
margin-top: 1em;
font-size: 1.3rem;
}
}
Hope from this tutorial you got to know how I made this Simple Tic-Tac-Toe JavaScript game.
Not only this but earlier I have shared more advanced game tutorials. Earlier I shared another JavaScript Tic-Tac-Toe which is basically made by Simple Code. Where you can play with two users rather than with the computer. Be sure to comment how you like this project(How to Recreate Tic-Tac-Toe in Vanilla JavaScript).
Original article source at: https://foolishdeveloper.com/
1648115675
Germany was the first country to recognize #Bitcoins as “units of value” and that they could be classified as a “financial instrument.”
Legal regulation for the decentralized industry in Germany is ongoing. Now, 16% of the German population 18 to 60 are #crypto investors.
These people who own #cryptocurrencies or have traded cryptocurrencies in the past six months.
41% of these #crypto investors intend to increase the share of their investments in #crypto in the next six months. Another 13% of Germans are #crypto-curious.
They intend to invest in #cryptocurrencies too. Yet, only 23% of the #crypto-curious said they are highly likely to invest, with the rest remaining hesitant.
1624279585
Today we look at my message toward Bitcoin’s latest crypto crash. Will the price go into a bear market or are we still bullish? I show you my latest trade for our phemex BTC Trading competition.
📺 The video in this post was made by BitBoy Crypto
The origin of the article: https://www.youtube.com/watch?v=424L9Zk_zI8
🔺 DISCLAIMER: The article is for information sharing. The content of this video is solely the opinions of the speaker who is not a licensed financial advisor or registered investment advisor. Not investment advice or legal advice.
Cryptocurrency trading is VERY risky. Make sure you understand these risks and that you are responsible for what you do with your money
🔥 If you’re a beginner. I believe the article below will be useful to you ☞ What You Should Know Before Investing in Cryptocurrency - For Beginner
⭐ ⭐ ⭐The project is of interest to the community. Join to Get free ‘GEEK coin’ (GEEKCASH coin)!
☞ **-----CLICK HERE-----**⭐ ⭐ ⭐
Thanks for visiting and watching! Please don’t forget to leave a like, comment and share!
#bitcoin #blockchain #bitcoin crash #crypto bears 2021 #crypto #latest bitcoin crash (dire message to crypto bears 2021)
1624399200
In today’s video, we will discuss crypto taking over the world as we see nations starting to accept Bitcoin as legal tender. Is mass crypto adoption around the corner? Politicians now want to share their cryptocurrency knowledge or lack thereof. Will we see Cardano, Ethereum, and other top altcoins accepted as legal tender in the future?
📺 The video in this post was made by BitBoy Crypto
The origin of the article: https://www.youtube.com/watch?v=qSMgK2u4lfw
🔺 DISCLAIMER: The article is for information sharing. The content of this video is solely the opinions of the speaker who is not a licensed financial advisor or registered investment advisor. Not investment advice or legal advice.
Cryptocurrency trading is VERY risky. Make sure you understand these risks and that you are responsible for what you do with your money
🔥 If you’re a beginner. I believe the article below will be useful to you ☞ What You Should Know Before Investing in Cryptocurrency - For Beginner
⭐ ⭐ ⭐The project is of interest to the community. Join to Get free ‘GEEK coin’ (GEEKCASH coin)!
☞ **-----CLICK HERE-----**⭐ ⭐ ⭐
Thanks for visiting and watching! Please don’t forget to leave a like, comment and share!
#bitcoin #blockchain #bitcoin news #angry woman yells at crypto #crypto #bitcoin news: changing the world (angry woman yells at crypto)
1624140000
Around the Blockchain is your favorite Cryptocurrency show discussing Bitcoin, Ethereum, Cardano, and the top altcoins. Our four crypto experts include CryptoFace, CryptoWendyO, Blockchain Boy, and Ben Armstrong. Tune in for their insightful crypto analysis!
Today we’ll be discussing some HUGE additions to Coinbase Pro. What do these Coinbase listings mean for crypto? There are some very impactful buys on Bitcoin that might initiate a drastic price change. Finally, can your Bitcoin buy you a Buick soon? GM has just recently made some very interesting comments.
📺 The video in this post was made by BitBoy Crypto
The origin of the article: https://www.youtube.com/watch?v=oTyjW8hWKHg
🔺 DISCLAIMER: The article is for information sharing. The content of this video is solely the opinions of the speaker who is not a licensed financial advisor or registered investment advisor. Not investment advice or legal advice.
Cryptocurrency trading is VERY risky. Make sure you understand these risks and that you are responsible for what you do with your money
🔥 If you’re a beginner. I believe the article below will be useful to you ☞ What You Should Know Before Investing in Cryptocurrency - For Beginner
⭐ ⭐ ⭐The project is of interest to the community. Join to Get free ‘GEEK coin’ (GEEKCASH coin)!
☞ **-----CLICK HERE-----**⭐ ⭐ ⭐
Thanks for visiting and watching! Please don’t forget to leave a like, comment and share!
#bitcoin #blockchain #massive bitcoin changes ahead #crypto #best 2021 crypto update #massive bitcoin changes ahead (best 2021 crypto update)