Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
import java.util.*; public class Mastermind { public static void main(String[] args) { Scanner s = new Scanner(System.in); //scanner int Scanner t = new Scanner(System.in); //scanner String Random r = new Random(); //random int chiffreschoisis[] = {0,0,0,0};//chiffres a deviner int chiffregen[] = {0,0,0,0};//chiffres entrees int bonnerep[] = {0,0,0}; //riens, vaches, teauraux boolean gen = false; //generation du nombre a deviner boolean game = false; //gestion du jeu boolean enChoix = false; //gestion du choix de l'ordi boolean testDeja = false; //regarde les nombres du tableau valPoss boolean reponOk = false; //pour éviter que le joueur ne réponde n'importe quoi boolean working = false; int tours = 0; //compte les tours int valeurOrdi = 0; //valeur donnée par l'ordi int[] valPoss = new int[4636]; //liste des valeurs possibles int[] valaChois = new int[16]; //ensemble des valeurs a choisir au pif int taurPoss[] = {-1,-1,-1,-1}; //chiffres qui sont peut-être teauraux int vachPoss[] = {-1,-1,-1,-1}; //chiffres qui sont peut-être vaches int taurSur[] = {-1,-1,-1,-1}; //chiffres qui sont teauraux int vachSur[] = {-1,-1,-1,-1}; //chiffres qui sont vaches int vide[] = {-1,-1,-1,-1,-1,-1,-1,-1,-1}; //chiffres non présents int valDecom[][][] = {{{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}, {{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}, {{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}, //[vaches][taureaux][pos du chiffre] {{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}};//chacun des nombnres de valuse, mais décomposés int valuse[][] = {{0,0,0,0},{0,0,0,0},{0,0,0,0}};//[vaches][taureaux] int n = 0; //sert de curseur dans vide[] int u = 0; //sert de curseur dans valPoss int w = 0; //curseur dans chiffreschoisis int com = 0; //compteurs dans int repOrdi = 0; int choix = 0; int monChoix = 0; System.out.println("Jouer en mode \"IA\" (l'ordinateur détermine le chiffre) où \"Normal\" (vous determinez le chiffre) ?."); String mode = t.nextLine(); if (mode.equals("IA")||mode.equals("iA")||mode.equals("Ia")||mode.equals("ia"))//mode IA { while (gen == false)//on génère le chiffre que l'IA va tenter de deviner { System.out.println("Choisissez un chiffre entre 1023 et 9876."); System.out.println("Il ne peut y avoir deux fois le même chiffre."); monChoix = s.nextInt(); //entre un nombre int c1, c2, c3, c4; c1 = monChoix%10; c2 = (monChoix%100)/10; c3 = (monChoix%1000)/100; c4 = (monChoix%10000)/1000; //isole les chiffres if (c1 != c2 && c3 != c4 && c1!=c3 && c2 !=c4 && c1 != c4 && c2 != c3) //teste chacun des chiffres { chiffreschoisis[0]=c4; //atribue le dernier chiffre a la case 0 chiffreschoisis[1]=c3; //atribue le chiffre 3 a la case 1 chiffreschoisis[2]=c2; //atribue le chiffre 2 a la case 2 chiffreschoisis[3]=c1; //atribue le chiffre 1 a la case 3 gen = true; // fin de la gestion du nombre } else { System.out.println("Conditions non-respectées."); } } while (game == false)//l'IA va trouver ce chiffre { enChoix = false; testDeja = false; int o = 0; //compte les tours de la boucle suivante, correspond a une case de valPoss while (enChoix == false)//l'ordinateur choisit un nombre { testDeja = false; enChoix = false; working = false; o = 0; while (testDeja == false) { while (working == false)//on va décomposer toutes les réponses possibles { int uu = 0; int v = 0; while (u < 3)//on remplit valDecom { while (v < 3) { valDecom[uu][v][0] = (valuse[uu][v]%10000)/1000; valDecom[uu][v][1] = (valuse[uu][v]%1000)/100; valDecom[uu][v][2] = (valuse[uu][v]%100)/10; valDecom[uu][v][3] = valuse[uu][v]%10; v++; } v=0; u++; } //Test des valeurs //[vaches][taureaux][pos du chiffre] if (valDecom[1][0][0] == valDecom[1][1][0]) { vachPoss[com] = valDecom[0][0][0]; // com++; } working=true; } choix = r.nextInt((9877-1023))+1023; //choisit un nombre int f1, f2, f3, f4; f1 = choix%10; f2 = (choix%100)/10; f3 = (choix%1000)/100; f4 = (choix%10000)/1000; //isole les chiffres if (f1 != f2 && f3 != f4 && f1!=f3 && f2 !=f4 && f1 != f4 && f2 != f3) //teste chacun des chiffres { chiffreschoisis[0]=f4; //atribue le dernier chiffre a la case 0 chiffreschoisis[1]=f3; //atribue le chiffre 3 a la case 1 chiffreschoisis[2]=f2; //atribue le chiffre 2 a la case 2 chiffreschoisis[3]=f1; //atribue le chiffre 1 a la case 3 testDeja = true; // fin de la gestion du nombre } } while (o < 4636) { if (choix != valPoss[o]) //on regarde si le nombre n'a pas encore été déjà choisit { testDeja = true; valPoss[o]=choix; //entre la valeur dans le tableau o = 9999; //sort de la boucle enChoix = true; // fin de la gestion du nombre } else { o++; //on passe a la case d'après } } } repOrdi = chiffreschoisis[0]*1000+chiffreschoisis[1]*100+chiffreschoisis[2]*10+chiffreschoisis[3]; System.out.println("L'ordinateur a choisi le nombre : " + repOrdi); if (repOrdi == monChoix) { System.out.println("L'ordinateur a trouvé la bonne réponse au bout de " + tours + " tours."); game = true; } else { reponOk = false; while (reponOk == false) { System.out.print("Combien de vaches ? "); int vaches = s.nextInt(); System.out.print("\nCombien de taureaux ? "); int taureaux = s.nextInt(); if (vaches < 0 || vaches > 4 || taureaux < 0 || taureaux > 3 || (taureaux + vaches) > 4)//le joueur a répondu n'importe quoi { System.out.println("\nUn peu de sérieux s'il vous plait."); } else { if (tours > 4636) { System.out.println("Vous avez menti, et piégé l'IA."); } reponOk = true; tours++; int y,x; //compteurs des boucles ci-dessous valPoss[u] = repOrdi; //on inclut le choix de l'ordi dans valPoss, afin qu'il ne le tire pas de nouveau //cas extrêmes valuse[vaches][taureaux] = repOrdi; } } } } } else //mode normal si on ne choisit pas l'IA { System.out.println("L'ordinateur choisit un chiffre entre 1023 et 9876."); while (gen == false) { choix = r.nextInt(9877)+1023; //choisit un nombre int c1, c2, c3, c4; c1 = choix%10; c2 = (choix%100)/10; c3 = (choix%1000)/100; c4 = (choix%10000)/1000; //isole les chiffres if (c1 != c2 && c3 != c4 && c1!=c3 && c2 !=c4 && c1 != c4 && c2 != c3) //teste chacun des chiffres { chiffreschoisis[0]=c4; //atribue le dernier chiffre a la case 0 chiffreschoisis[1]=c3; //atribue le chiffre 3 a la case 1 chiffreschoisis[2]=c2; //atribue le chiffre 2 a la case 2 chiffreschoisis[3]=c1; //atribue le chiffre 1 a la case 3 gen = true; // fin de la gestion du nombre System.out.println("L'ordinateur a choisi un nombre."); } else { } } while (game == false) { boolean betise = false; int rep = 0; while (betise == false) { System.out.println("Entrez un nombre entre 1023 et 9876."); rep = s.nextInt(); if (rep < 1023 || rep > 9876) System.out.println("Un peu de sérieux. S'il vous plait."); else betise = true; } bonnerep[0]=0;bonnerep[1]=0;bonnerep[2]=0; // reinitialise le nombre de vaches & taureaux int r1,r2,r3,r4; r1 = rep%10; r2 = (rep%100)/10; r3 = (rep%1000)/100; r4 = (rep%10000)/1000;//isole les chiffres //teste chacun des chiffres isolés pour voir si ils sont taureaux ou vaches if (r4 == chiffreschoisis[0])//taureaux { bonnerep[2]++; } else if (r4 == chiffreschoisis[1] || r4 == chiffreschoisis[2] || r4 == chiffreschoisis[3])//vaches { bonnerep[1]++; } else { bonnerep[0]++; } if (r3 == chiffreschoisis[1])//taureaux { bonnerep[2]++; } else if (r3 == chiffreschoisis[0] || r3 == chiffreschoisis[2] || r3 == chiffreschoisis[3])//vaches { bonnerep[1]++; } else { bonnerep[0]++; } if (r2 == chiffreschoisis[2])//taureaux { bonnerep[2]++; } else if (r2 == chiffreschoisis[1] || r2 == chiffreschoisis[0] || r2 == chiffreschoisis[3])//vaches { bonnerep[1]++; } else { bonnerep[0]++; } if (r1 == chiffreschoisis[3])//taureaux { bonnerep[2]++; } else if (r1 == chiffreschoisis[1] || r1 == chiffreschoisis[2] || r1 == chiffreschoisis[0])//vaches { bonnerep[1]++; } else { bonnerep[0]++; } if (bonnerep[2]==4)//victoire { System.out.println("Victoire ! Le bon nombre était : " + chiffreschoisis[0]+ chiffreschoisis[1]+chiffreschoisis[2]+chiffreschoisis[3] + "\n"+ "Il vous a fallu " + (tours+1) + " essais."); game = false; //on sort de la boucle } else { System.out.println("Il y a " + bonnerep[1] + " vache(s) et " + bonnerep[2] + " taureau(x)."); tours++; } } } } }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
I made $15,000 * 2 hours
CSS | 20 min ago | 0.99 KB
✅ API Glitch (Docs Leak)
CSS | 21 min ago | 0.99 KB
Custom Placeholder: Event Image using alt tag...
12 hours ago | 0.50 KB
Untitled
Bash | 22 hours ago | 1.17 KB
Using Prepared statement with bind vars to pr...
Go | 1 day ago | 3.67 KB
rc
2 days ago | 2.49 KB
Stripe Session Vars
2 days ago | 0.67 KB
[TLF 16] Hylandra's File / Introduction
2 days ago | 3.37 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!