@echo off title Battleships Game setlocal EnableDelayedExpansion :: Board dimensions set width=5 set height=5 :: Set empty player's and computer's boards for /L %%i in (1,1,%width%) do ( for /L %%j in (1,1,%height%) do ( set player_%%i%%j=. set computer_%%i%%j=. ) ) :: Let the player place their ship :place_ship cls echo Place your ship on the board. echo Enter the coordinates in the format X Y (e.g., 2 3) set /P "shipX=Enter X coordinate (1-%width%): " set /P "shipY=Enter Y coordinate (1-%height%): " set player_%shipX%%shipY%=S cls :: Set computer's ship at a random position set /A compShipX=%random% %% %width% + 1 set /A compShipY=%random% %% %height% + 1 set computer_%compShipX%%compShipY%=S :: Function to display the player's board with ship and computer's shots :display_board echo Your Board: for /L %%i in (1,1,%width%) do ( for /L %%j in (1,1,%height%) do ( if "!player_%%i%%j!"=="S" ( set display=S ) else if "!player_%%i%%j!"=="X" ( set display=X ) else if "!player_%%i%%j!"=="O" ( set display=O ) else ( set display=. ) set /P cell=!display!