Skip to content
Snippets Groups Projects
Commit 865bc2cc authored by Benoît Harrault's avatar Benoît Harrault
Browse files

First commit, init application

parent 94edb0c7
No related branches found
No related tags found
No related merge requests found
Pipeline #784 failed
Showing
with 425 additions and 0 deletions
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png

1.25 KiB

ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png

1.85 KiB

ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png

2.6 KiB

ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png

2.6 KiB

ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png

3.74 KiB

ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png

1.84 KiB

ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png

3.22 KiB

ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png

3.53 KiB

{
"images" : [
{
"idiom" : "universal",
"filename" : "LaunchImage.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "LaunchImage@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "LaunchImage@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png

68 B

ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png

68 B

ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png

68 B

# Launch Screen Assets
You can customize the launch screen with your own desired assets by replacing the image files in this directory.
You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images.
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Ydg-fD-yQy"/>
<viewControllerLayoutGuide type="bottom" id="xbc-2k-c8Z"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" image="LaunchImage" translatesAutoresizingMaskIntoConstraints="NO" id="YRO-k0-Ey4">
</imageView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="YRO-k0-Ey4" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="1a2-6s-vTC"/>
<constraint firstItem="YRO-k0-Ey4" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="4X2-HB-R7a"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
<resources>
<image name="LaunchImage" width="168" height="185"/>
</resources>
</document>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<scenes>
<!--Flutter View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="FlutterViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
</document>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>puissance4</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
</plist>
#import "GeneratedPluginRegistrant.h"
\ No newline at end of file
import 'package:puissance4/coordinate.dart';
import 'match_page.dart';
class Board {
List<List<Color>> _boxes = List.generate(
7,
(i) => List.generate(
7,
(i) => null,
),
);
Board();
Board.from(List<List<Color>> boxes) {
_boxes = boxes;
}
Color getBox(Coordinate coordinate) => _boxes[coordinate.col][coordinate.row];
int getColumnTarget(int col) => _boxes[col].lastIndexOf(null);
void setBox(Coordinate coordinate, Color player) =>
_boxes[coordinate.col][coordinate.row] = player;
void reset() {
_boxes.forEach((r) => r.forEach((p) => p = null));
}
bool checkWinner(Coordinate coordinate, Color player) {
return checkHorizontally(coordinate, player) ||
checkVertically(coordinate, player) ||
checkDiagonally(coordinate, player);
}
bool checkHorizontally(Coordinate coordinate, Color player) {
var r = 0;
for (;
coordinate.col + r < 7 &&
r < 4 &&
getBox(coordinate.copyWith(col: coordinate.col + r)) == player;
++r) {}
if (r >= 4) {
return true;
}
var l = 0;
for (;
coordinate.col - l >= 0 &&
l < 4 &&
getBox(coordinate.copyWith(col: coordinate.col - l)) == player;
++l) {}
if (l >= 4 || l + r >= 5) {
return true;
}
return false;
}
bool checkDiagonally(Coordinate coordinate, Color player) {
var ur = 0;
for (;
coordinate.col + ur < 7 &&
coordinate.row + ur < 7 &&
ur < 4 &&
getBox(coordinate.copyWith(
col: coordinate.col + ur,
row: coordinate.row + ur,
)) ==
player;
++ur) {}
if (ur >= 4) {
return true;
}
var dl = 0;
for (;
coordinate.col - dl >= 0 &&
coordinate.row - dl >= 0 &&
dl < 4 &&
getBox(coordinate.copyWith(
col: coordinate.col - dl,
row: coordinate.row - dl,
)) ==
player;
++dl) {}
if (dl >= 4 || dl + ur >= 5) {
return true;
}
var dr = 0;
for (;
coordinate.col + dr < 7 &&
coordinate.row - dr >= 0 &&
dr < 4 &&
getBox(coordinate.copyWith(
col: coordinate.col + dr,
row: coordinate.row - dr,
)) ==
player;
++dr) {}
if (dr >= 4) {
return true;
}
var ul = 0;
for (;
coordinate.col - ul >= 0 &&
coordinate.row + ul < 7 &&
ul < 4 &&
getBox(coordinate.copyWith(
col: coordinate.col - ul,
row: coordinate.row + ul,
)) ==
player;
++ul) {}
if (ul >= 4 || dr + ul >= 5) {
return true;
}
return false;
}
bool checkVertically(Coordinate coordinate, Color player) {
var u = 0;
for (;
coordinate.row + u < 7 &&
u < 4 &&
getBox(coordinate.copyWith(
row: coordinate.row + u,
)) ==
player;
++u) {}
if (u >= 4) {
return true;
}
var d = 0;
for (;
coordinate.row - d >= 0 &&
d < 4 &&
getBox(coordinate.copyWith(
row: coordinate.row - d,
)) ==
player;
++d) {}
if (d >= 4 || d + u >= 5) {
return true;
}
return false;
}
Board clone() {
return Board.from(_boxes.map((c) => c.map((b) => b).toList()).toList());
}
}
class Coordinate {
final int row, col;
Coordinate(
this.col,
this.row,
);
Coordinate copyWith({
int col,
int row,
}) =>
Coordinate(
col ?? this.col,
row ?? this.row,
);
}
import 'dart:math';
import 'board.dart';
import 'coordinate.dart';
import 'match_page.dart';
abstract class Cpu {
final Color color;
final Random _random = Random(DateTime.now().millisecond);
Cpu(this.color);
Color get otherPlayer => color == Color.RED ? Color.YELLOW : Color.RED;
Future<int> chooseCol(Board board);
}
class DumbCpu extends Cpu {
DumbCpu(Color player) : super(player);
Color get otherPlayer => color == Color.RED ? Color.YELLOW : Color.RED;
@override
Future<int> chooseCol(Board board) async {
await Future.delayed(Duration(seconds: _random.nextInt(2)));
int col = _random.nextInt(7);
return col;
}
@override
String toString() => 'DUMB CPU';
}
class HarderCpu extends Cpu {
HarderCpu(Color player) : super(player);
@override
Future<int> chooseCol(Board board) async {
final List<double> scores = List.filled(7, 0);
await Future.delayed(Duration(seconds: 1 + _random.nextInt(2)));
return _compute(board, 0, 1, scores);
}
int _compute(Board board, int step, int deepness, List<double> scores) {
for (var i = 0; i < 7; ++i) {
final boardCopy = board.clone();
final target = boardCopy.getColumnTarget(i);
if (target == -1) {
scores[i] = null;
continue;
}
final coordinate = Coordinate(i, target);
boardCopy.setBox(coordinate, color);
if (boardCopy.checkWinner(coordinate, color)) {
scores[i] += deepness / (step + 1);
continue;
}
for (var j = 0; j < 7; ++j) {
final target = boardCopy.getColumnTarget(j);
if (target == -1) {
continue;
}
final coordinate = Coordinate(j, target);
boardCopy.setBox(coordinate, otherPlayer);
if (boardCopy.checkWinner(coordinate, otherPlayer)) {
scores[i] -= deepness / (step + 1);
continue;
}
if (step + 1 < deepness) {
_compute(board, step + 1, deepness, scores);
}
}
}
return _getBestScoreIndex(scores);
}
int _getBestScoreIndex(List<double> scores) {
int bestScoreIndex = scores.indexWhere((s) => s != null);
scores.asMap().forEach((index, score) {
if (score != null &&
(score > scores[bestScoreIndex] ||
(score == scores[bestScoreIndex] && _random.nextBool()))) {
bestScoreIndex = index;
}
});
return bestScoreIndex;
}
@override
String toString() => 'HARDER CPU';
}
class HardestCpu extends HarderCpu {
HardestCpu(Color player) : super(player);
@override
Future<int> chooseCol(Board board) async {
final List<double> scores = List.filled(7, 0);
await Future.delayed(Duration(seconds: 2 + _random.nextInt(2)));
return _compute(board, 0, 4, scores);
}
@override
String toString() => 'HARDEST CPU';
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment