How would I center a multiline ascii art - c++

I'm new to C++ I have a ASCII art that looks like this
string title =
" _____ ____ _ _ _____ _ ______ _____ _____ _ \n"
" / ____/ __ \\| \\ | |/ ____| | | ____|/ ____/ ____| |\n"
"| | | | | | \\| | (___ | | | |__ | (___| (___ | |\n"
"| | | | | | . ` |\\___ \\| | | __| \\___ \\\\___ \\| |\n"
"| |___| |__| | |\\ |____) | |____| |____ ____) |___) |_|\n"
" \\_____\\____/|_| \\_|_____/|______|______|_____/_____/(_)\n";
I want to paste this ASCII art in the console but I don't want it to be on the left side I want it to be centered how would I go about centering this ASCII art in the console.

Alright I found this solution where you can make a array of the lines of the ascii art and then add 50 spaces before each line.
int main()
{
string title[6] = {" _____ ____ _ _ _____ _ ______ _____ _____ _ ", " / ____/ __ \\| \\ | |/ ____| | | ____|/ ____/ ____| |", "| | | | | | \\| | (___ | | | |__ | (___| (___ | |", "| | | | | | . ` |\\___ \\| | | __| \\___ \\\\___ \\| |", "| |___| |__| | |\\ |____) | |____| |____ ____) |___) |_|", " \\_____\\____/|_| \\_|_____/|______|______|_____/_____/(_)"};
for (size_t i = 0; i < 6; i++)
cout << string(50, ' ') + title[i] << endl;
return 0;
}

Here's an example if you're using fmt with center alignment.
#include <string>
#include <fmt/core.h>
void print(std::string s){
int width = 100;
fmt::print("{:*^{}}\n", s, width); // '*' fills the blank space so it's easier to see the center alignment effect.
}
int main(){
print(" _____ ____ _ _ _____ _ ______ _____ _____ _ ");
print(" / ____/ __ \\| \\ | |/ ____| | | ____|/ ____/ ____| |");
print("| | | | | | \\| | (___ | | | |__ | (___| (___ | |");
print("| | | | | | . ` |\\___ \\| | | __| \\___ \\\\___ \\| |");
print("| |___| |__| | |\\ |____) | |____| |____ ____) |___) |_|");
print(" \\_____\\____/|_| \\_|_____/|______|______|_____/_____/(_)");
return 0;
}
Synax for fmt
Live Demo
Output
********************** _____ ____ _ _ _____ _ ______ _____ _____ _ **********************
********************** / ____/ __ \| \ | |/ ____| | | ____|/ ____/ ____| |**********************
**********************| | | | | | \| | (___ | | | |__ | (___| (___ | |**********************
**********************| | | | | | . ` |\___ \| | | __| \___ \\___ \| |**********************
**********************| |___| |__| | |\ |____) | |____| |____ ____) |___) |_|**********************
********************** \_____\____/|_| \_|_____/|______|______|_____/_____/(_)**********************

Related

difference between size_t (*B)[N] and size_t *B[N]

what's the difference between these two lines of code in c++?
size_t (*B)[N] = new size_t[N][N]; and
size_t *B[N] = new size_t[N][N];
first one compiles correctly but with second line, g++ gives this error
matrixim.cpp:43:20: error: array must be initialized with a brace-enclosed initializer
43 | size_t *B[N] = new size_t[N][N];
size_t *B[N]
Here, B is an array of N pointers to size_t
size_t (*B)[N]
Here, B is a pointer to an array of N size_ts
Both of these constructs could be used to create something approximating a 2-dimensional array, but their layout in memory is very different.
size_t *B[N] would look something like this:
B +-------------+-------------+-----+-------------+
+--------+ | B[0][0] | B[0][1] | ... | B[0][N-1] |
| B[0] +--->+-------------+-------------+-----+-------------+
+--------+
| B[1] +--->+-------------+-------------+-----+-------------+
+--------+ | B[1][0] | B[1][1] | ... | B[1][N-1] |
| | +-------------+-------------+-----+-------------+
| ... |
| |
+--------+
| B[N-1] +--->+-------------+-------------+-----+-------------+
+--------+ | B[N-1][0] | B[N-1][1] | ... | B[N-1][N-1] |
+-------------+-------------+-----+-------------+
B is an array of N pointers to size_t, each of which points to the first element of an array of N size_t.
size_t (*B)[N] would look something like this:
B +---------------------------------------------------+
+----+ | B[0] |
| +--->+ +-------------+-------------+-----+-------------+ |
+----+ | | B[0][0] | B[0][1] | ... | B[0][N-1] | |
| +-------------+-------------+-----+-------------+ |
+---------------------------------------------------+
| B[1] |
| +-------------+-------------+-----+-------------+ |
| | B[1][0] | B[1][1] | ... | B[1][N-1] | |
| +-------------+-------------+-----+-------------+ |
+---------------------------------------------------+
| |
| ... |
| |
+---------------------------------------------------+
| B[N-1] |
| +-------------+-------------+-----+-------------+ |
| | B[N-1][0] | B[N-1][1] | ... | B[N-1][N-1] | |
| +-------------+-------------+-----+-------------+ |
+---------------------------------------------------+
Here, B is a pointer to the first element of an array of N arrays of N size_t.

The bean 'AmazonEc2InstanceDataPropertySourcePostProcessor', defined in null, could not be registered

I try to migrate spring from 1.5.7 version to 2.1.5 and this exception occurred.
The stack trace listed below.
2020-02-18 07:23:02.056 INFO 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2020-02-18 07:23:02.226 INFO 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available
2020-02-18 07:23:02.226 WARN 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/application/dockerEE,solrWriterEnabled,writerBatchSize5000,aws_integration3a,commondb,neo,reviewModelIndexingDisabled/aws_integration3a": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
2020-02-18 07:23:02.229 INFO 1 --- [ main] c.j.itemdiscovery.index.Application : The following profiles are active: dockerEE,solrWriterEnabled,writerBatchSize5000,aws_integration3a,commondb,neo,reviewModelIndexingDisabled
2020-02-18 07:23:03.480 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2020-02-18 07:23:03.510 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 23ms. Found 0 repository interfaces.
2020-02-18 07:23:03.515 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2020-02-18 07:23:03.520 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 5ms. Found 0 repository interfaces.
2020-02-18 07:23:03.575 WARN 1 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'AmazonEc2InstanceDataPropertySourcePostProcessor' defined in null: Cannot register bean definition [Generic bean: class [org.springframework.cloud.aws.context.config.AmazonEc2InstanceDataPropertySourcePostProcessor]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] for bean 'AmazonEc2InstanceDataPropertySourcePostProcessor': There is already [Generic bean: class [org.springframework.cloud.aws.context.config.AmazonEc2InstanceDataPropertySourcePostProcessor]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] bound.
2020-02-18 07:23:03.589 INFO 1 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-02-18 07:23:03.593 ERROR 1 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'AmazonEc2InstanceDataPropertySourcePostProcessor', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
This is gradle properties of indexer project
apply plugin: 'application'
apply plugin: 'org.springframework.boot'
configurations {
compile.exclude module: 'spring-boot-starter-tomcat'
compile.exclude module: 'slf4j-log4j12'
compile.exclude module: 'log4j-slf4j-impl'
compile.exclude module: 'jms-api'
compile.exclude module: 'tibjms'
compile.exclude module: 'spring-jms'
compile.extendsFrom(springBootCommon, springCloudCommon)
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
dependencies {
dependencySet(group: 'org.apache.solr', version: '6.4.1') {
entry 'solr-solrj'
}
}
}
dependencies {
compile project(':tdm-integration-common')
compileOnly 'org.projectlombok:lombok'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'com.tngtech.java', name: 'junit-dataprovider', version: '1.12.0'
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
}
Dependencies tree
compileClasspath - Compile classpath for source set 'main'.
+--- project :tdm-integration-common
| +--- com.dig.platform:cassandra:2.1.16
| | +--- com.datastax.dse:dse-java-driver-core:1.8.1
| | | +--- io.netty:netty-handler:4.0.56.Final -> 4.1.36.Final
| | | | +--- io.netty:netty-common:4.1.36.Final
| | | | +--- io.netty:netty-buffer:4.1.36.Final
| | | | | \--- io.netty:netty-common:4.1.36.Final
| | | | +--- io.netty:netty-transport:4.1.36.Final
| | | | | +--- io.netty:netty-common:4.1.36.Final
| | | | | +--- io.netty:netty-buffer:4.1.36.Final (*)
| | | | | \--- io.netty:netty-resolver:4.1.36.Final
| | | | | \--- io.netty:netty-common:4.1.36.Final
| | | | \--- io.netty:netty-codec:4.1.36.Final
| | | | +--- io.netty:netty-common:4.1.36.Final
| | | | +--- io.netty:netty-buffer:4.1.36.Final (*)
| | | | \--- io.netty:netty-transport:4.1.36.Final (*)
| | | +--- com.google.guava:guava:19.0
| | | +--- io.dropwizard.metrics:metrics-core:3.2.2 -> 3.1.2
| | | | \--- org.slf4j:slf4j-api:1.7.7 -> 1.7.26
| | | +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.26
| | | +--- com.github.jnr:jnr-ffi:2.1.7
| | | | +--- com.github.jnr:jffi:1.2.16
| | | | +--- org.ow2.asm:asm:5.0.3
| | | | +--- org.ow2.asm:asm-commons:5.0.3
| | | | | \--- org.ow2.asm:asm-tree:5.0.3
| | | | | \--- org.ow2.asm:asm:5.0.3
| | | | +--- org.ow2.asm:asm-analysis:5.0.3
| | | | | \--- org.ow2.asm:asm-tree:5.0.3 (*)
| | | | +--- org.ow2.asm:asm-tree:5.0.3 (*)
| | | | +--- org.ow2.asm:asm-util:5.0.3
| | | | | \--- org.ow2.asm:asm-tree:5.0.3 (*)
| | | | \--- com.github.jnr:jnr-x86asm:1.0.2
| | | \--- com.github.jnr:jnr-posix:3.0.44
| | | +--- com.github.jnr:jnr-ffi:2.1.7 (*)
| | | \--- com.github.jnr:jnr-constants:0.9.9
| | +--- com.google.guava:guava:19.0
| | +--- org.springframework.data:spring-data-cassandra:2.1.5.RELEASE -> 2.1.8.RELEASE
| | | +--- org.springframework:spring-context:5.1.7.RELEASE
| | | | +--- org.springframework:spring-aop:5.1.7.RELEASE
| | | | | +--- org.springframework:spring-beans:5.1.7.RELEASE
| | | | | | \--- org.springframework:spring-core:5.1.7.RELEASE
| | | | | | \--- org.springframework:spring-jcl:5.1.7.RELEASE
| | | | | \--- org.springframework:spring-core:5.1.7.RELEASE (*)
| | | | +--- org.springframework:spring-beans:5.1.7.RELEASE (*)
| | | | +--- org.springframework:spring-core:5.1.7.RELEASE (*)
| | | | \--- org.springframework:spring-expression:5.1.7.RELEASE
| | | | \--- org.springframework:spring-core:5.1.7.RELEASE (*)
| | | +--- org.springframework:spring-beans:5.1.7.RELEASE (*)
| | | +--- org.springframework:spring-core:5.1.7.RELEASE (*)
| | | +--- org.springframework:spring-tx:5.1.7.RELEASE
| | | | +--- org.springframework:spring-beans:5.1.7.RELEASE (*)
| | | | \--- org.springframework:spring-core:5.1.7.RELEASE (*)
| | | +--- org.springframework:spring-expression:5.1.7.RELEASE (*)
| | | +--- org.springframework.data:spring-data-commons:2.1.8.RELEASE
| | | | +--- org.springframework:spring-core:5.1.7.RELEASE (*)
| | | | +--- org.springframework:spring-beans:5.1.7.RELEASE (*)
| | | | \--- org.slf4j:slf4j-api:1.7.26
| | | \--- org.slf4j:slf4j-api:1.7.26
| | \--- org.projectlombok:lombok:1.16.12 -> 1.18.8
| +--- com.dig.platform:metrics:2.1.16
| | +--- org.springframework.boot:spring-boot-starter-actuator:2.1.5.RELEASE
| | | +--- org.springframework.boot:spring-boot-starter:2.1.5.RELEASE
| | | | +--- org.springframework.boot:spring-boot:2.1.5.RELEASE
| | | | | +--- org.springframework:spring-core:5.1.7.RELEASE (*)
| | | | | \--- org.springframework:spring-context:5.1.7.RELEASE (*)
| | | | +--- org.springframework.boot:spring-boot-autoconfigure:2.1.5.RELEASE
| | | | | \--- org.springframework.boot:spring-boot:2.1.5.RELEASE (*)
| | | | +--- org.springframework.boot:spring-boot-starter-logging:2.1.5.RELEASE
| | | | | +--- ch.qos.logback:logback-classic:1.2.3
| | | | | | +--- ch.qos.logback:logback-core:1.2.3
| | | | | | \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.26
| | | | | +--- org.apache.logging.log4j:log4j-to-slf4j:2.11.2
| | | | | | +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.26
| | | | | | \--- org.apache.logging.log4j:log4j-api:2.11.2
| | | | | \--- org.slf4j:jul-to-slf4j:1.7.26
| | | | | \--- org.slf4j:slf4j-api:1.7.26
| | | | +--- javax.annotation:javax.annotation-api:1.3.2
| | | | \--- org.springframework:spring-core:5.1.7.RELEASE (*)
| | | +--- org.springframework.boot:spring-boot-actuator-autoconfigure:2.1.5.RELEASE
| | | | +--- org.springframework.boot:spring-boot-actuator:2.1.5.RELEASE
| | | | | \--- org.springframework.boot:spring-boot:2.1.5.RELEASE (*)
| | | | +--- org.springframework.boot:spring-boot-autoconfigure:2.1.5.RELEASE (*)
| | | | +--- com.fasterxml.jackson.core:jackson-databind:2.9.8
| | | | | +--- com.fasterxml.jackson.core:jackson-annotations:2.9.0
| | | | | \--- com.fasterxml.jackson.core:jackson-core:2.9.8
| | | | +--- org.springframework:spring-core:5.1.7.RELEASE (*)
| | | | \--- org.springframework:spring-context:5.1.7.RELEASE (*)
| | | \--- io.micrometer:micrometer-core:1.1.4
| | | +--- org.hdrhistogram:HdrHistogram:2.1.9
| | | \--- org.latencyutils:LatencyUtils:2.0.3
| | +--- org.springframework.cloud:spring-cloud-config-client:2.1.1.RELEASE
| | | +--- org.springframework.boot:spring-boot-autoconfigure:2.1.3.RELEASE -> 2.1.5.RELEASE (*)
| | | +--- org.springframework.cloud:spring-cloud-commons:2.1.1.RELEASE
| | | | \--- org.springframework.security:spring-security-crypto:5.1.4.RELEASE -> 5.1.5.RELEASE
| | | +--- org.springframework.cloud:spring-cloud-context:2.1.1.RELEASE
| | | | \--- org.springframework.security:spring-security-crypto:5.1.4.RELEASE -> 5.1.5.RELEASE
| | | +--- org.springframework:spring-web:5.1.5.RELEASE -> 5.1.7.RELEASE
| | | | +--- org.springframework:spring-beans:5.1.7.RELEASE (*)
| | | | \--- org.springframework:spring-core:5.1.7.RELEASE (*)
| | | +--- com.fasterxml.jackson.core:jackson-annotations:2.9.0
| | | \--- com.fasterxml.jackson.core:jackson-databind:2.9.8 (*)
| | \--- io.micrometer:micrometer-registry-prometheus:1.1.2 -> 1.1.4
| | +--- io.micrometer:micrometer-core:1.1.4 (*)
| | \--- io.prometheus:simpleclient_common:0.5.0
| | \--- io.prometheus:simpleclient:0.5.0
| +--- com.dig.platform:feature-logging-logback:1.9.20
| | \--- ch.qos.logback:logback-classic:1.1.7 -> 1.2.3 (*)
| +--- org.springframework:spring-context:5.1.7.RELEASE (*)
| +--- com.datastax.dse:dse-java-driver-mapping:1.8.1
| | +--- com.datastax.dse:dse-java-driver-core:1.8.1 (*)
| | +--- com.google.guava:guava:19.0
| | \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.26
| +--- com.datastax.dse:dse-java-driver-extras:1.8.1
| | +--- com.datastax.dse:dse-java-driver-core:1.8.1 (*)
| | \--- com.google.guava:guava:19.0
| +--- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.8.6 -> 2.9.8
| | +--- org.yaml:snakeyaml:1.23
| | \--- com.fasterxml.jackson.core:jackson-core:2.9.8
| +--- com.fasterxml.jackson.core:jackson-databind:2.8.6 -> 2.9.8 (*)
| +--- com.fasterxml.jackson.core:jackson-core:2.8.6 -> 2.9.8
| +--- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.8.6 -> 2.9.8
| | +--- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:2.9.8
| | | +--- com.fasterxml.jackson.core:jackson-core:2.9.8
| | | \--- com.fasterxml.jackson.core:jackson-databind:2.9.8 (*)
| | \--- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.9.8
| | +--- com.fasterxml.jackson.core:jackson-annotations:2.9.0
| | +--- com.fasterxml.jackson.core:jackson-core:2.9.8
| | \--- com.fasterxml.jackson.core:jackson-databind:2.9.8 (*)
| +--- com.google.code.gson:gson:2.8.0 -> 2.8.5
| +--- org.json:json:20180130
| +--- org.apache.cxf:cxf-core:3.1.12
| | +--- org.codehaus.woodstox:woodstox-core-asl:4.4.1
| | | \--- org.codehaus.woodstox:stax2-api:3.1.4
| | \--- org.apache.ws.xmlschema:xmlschema-core:2.2.2
| +--- org.apache.cxf:cxf-rt-rs-client:3.1.12
| | +--- org.apache.cxf:cxf-rt-transports-http:3.1.12
| | | \--- org.apache.cxf:cxf-core:3.1.12 (*)
| | +--- org.apache.cxf:cxf-core:3.1.12 (*)
| | \--- org.apache.cxf:cxf-rt-frontend-jaxrs:3.1.12
| | +--- org.apache.cxf:cxf-core:3.1.12 (*)
| | +--- javax.ws.rs:javax.ws.rs-api:2.0.1
| | +--- javax.annotation:javax.annotation-api:1.2 -> 1.3.2
| | \--- org.apache.cxf:cxf-rt-transports-http:3.1.12 (*)
| +--- org.apache.cxf:cxf-rt-transports-http-hc:3.1.12
| | +--- org.apache.cxf:cxf-core:3.1.12 (*)
| | +--- org.apache.cxf:cxf-rt-transports-http:3.1.12 (*)
| | +--- org.slf4j:slf4j-api:1.7.24 -> 1.7.26
| | +--- org.slf4j:jcl-over-slf4j:1.7.24 -> 1.7.26
| | | \--- org.slf4j:slf4j-api:1.7.26
| | +--- org.apache.httpcomponents:httpcore-nio:4.4.6 -> 4.4.11
| | | \--- org.apache.httpcomponents:httpcore:4.4.11
| | \--- org.apache.httpcomponents:httpasyncclient:4.1.3 -> 4.1.4
| | +--- org.apache.httpcomponents:httpcore:4.4.10 -> 4.4.11
| | +--- org.apache.httpcomponents:httpcore-nio:4.4.10 -> 4.4.11 (*)
| | \--- org.apache.httpcomponents:httpclient:4.5.6 -> 4.5.8
| | +--- org.apache.httpcomponents:httpcore:4.4.11
| | \--- commons-codec:commons-codec:1.11
| +--- org.apache.cxf:cxf-rt-frontend-jaxrs:3.1.12 (*)
| +--- com.amazonaws:aws-java-sdk-s3:1.11.180 -> 1.11.415
| | +--- com.amazonaws:aws-java-sdk-kms:1.11.415
| | | +--- com.amazonaws:aws-java-sdk-core:1.11.415
| | | | +--- org.apache.httpcomponents:httpclient:4.5.5 -> 4.5.8 (*)
| | | | +--- software.amazon.ion:ion-java:1.0.2
| | | | +--- com.fasterxml.jackson.core:jackson-databind:2.6.7.1 -> 2.9.8 (*)
| | | | +--- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.6.7 -> 2.9.8
| | | | | \--- com.fasterxml.jackson.core:jackson-core:2.9.8
| | | | \--- joda-time:joda-time:2.8.1 -> 2.10.2
| | | \--- com.amazonaws:jmespath-java:1.11.415
| | | \--- com.fasterxml.jackson.core:jackson-databind:2.6.7.1 -> 2.9.8 (*)
| | +--- com.amazonaws:aws-java-sdk-core:1.11.415 (*)
| | \--- com.amazonaws:jmespath-java:1.11.415 (*)
| +--- com.amazonaws:aws-java-sdk-core:1.11.180 -> 1.11.415 (*)
| +--- javax.jms:javax.jms-api:2.0.1
| +--- org.apache.solr:solr-solrj:6.4.1
| | +--- commons-io:commons-io:2.5
| | +--- org.apache.httpcomponents:httpclient:4.4.1 -> 4.5.8 (*)
| | +--- org.apache.httpcomponents:httpcore:4.4.1 -> 4.4.11
| | +--- org.apache.httpcomponents:httpmime:4.4.1 -> 4.5.8
| | +--- org.apache.zookeeper:zookeeper:3.4.6
| | +--- org.codehaus.woodstox:stax2-api:3.1.4
| | +--- org.codehaus.woodstox:woodstox-core-asl:4.4.1 (*)
| | +--- org.noggit:noggit:0.6
| | +--- org.slf4j:jcl-over-slf4j:1.7.7 -> 1.7.26 (*)
| | \--- org.slf4j:slf4j-api:1.7.7 -> 1.7.26
| +--- commons-codec:commons-codec:1.10 -> 1.11
| +--- commons-io:commons-io:2.5
| +--- org.apache.commons:commons-lang3:3.9 -> 3.8.1
| \--- org.hibernate:hibernate-validator:6.0.10.Final
| \--- org.hibernate.validator:hibernate-validator:6.0.10.Final -> 6.0.16.Final
| +--- javax.validation:validation-api:2.0.1.Final
| +--- org.jboss.logging:jboss-logging:3.3.2.Final
| \--- com.fasterxml:classmate:1.3.4 -> 1.4.0
+--- io.dropwizard.metrics:metrics-core:3.1.2 (*)
+--- org.projectlombok:lombok -> 1.18.8
+--- org.springframework.boot:spring-boot-starter-actuator -> 2.1.5.RELEASE (*)
+--- org.springframework.boot:spring-boot-starter-security -> 2.1.5.RELEASE
| +--- org.springframework.boot:spring-boot-starter:2.1.5.RELEASE (*)
| +--- org.springframework:spring-aop:5.1.7.RELEASE (*)
| +--- org.springframework.security:spring-security-config:5.1.5.RELEASE
| | +--- org.springframework.security:spring-security-core:5.1.5.RELEASE
| | | +--- org.springframework:spring-aop:5.1.6.RELEASE -> 5.1.7.RELEASE (*)
| | | +--- org.springframework:spring-beans:5.1.6.RELEASE -> 5.1.7.RELEASE (*)
| | | +--- org.springframework:spring-context:5.1.6.RELEASE -> 5.1.7.RELEASE (*)
| | | +--- org.springframework:spring-core:5.1.6.RELEASE -> 5.1.7.RELEASE (*)
| | | \--- org.springframework:spring-expression:5.1.6.RELEASE -> 5.1.7.RELEASE (*)
| | +--- org.springframework:spring-aop:5.1.6.RELEASE -> 5.1.7.RELEASE (*)
| | +--- org.springframework:spring-beans:5.1.6.RELEASE -> 5.1.7.RELEASE (*)
| | +--- org.springframework:spring-context:5.1.6.RELEASE -> 5.1.7.RELEASE (*)
| | \--- org.springframework:spring-core:5.1.6.RELEASE -> 5.1.7.RELEASE (*)
| \--- org.springframework.security:spring-security-web:5.1.5.RELEASE
| +--- org.springframework.security:spring-security-core:5.1.5.RELEASE (*)
| +--- org.springframework:spring-aop:5.1.6.RELEASE -> 5.1.7.RELEASE (*)
| +--- org.springframework:spring-beans:5.1.6.RELEASE -> 5.1.7.RELEASE (*)
| +--- org.springframework:spring-context:5.1.6.RELEASE -> 5.1.7.RELEASE (*)
| +--- org.springframework:spring-core:5.1.6.RELEASE -> 5.1.7.RELEASE (*)
| +--- org.springframework:spring-expression:5.1.6.RELEASE -> 5.1.7.RELEASE (*)
| \--- org.springframework:spring-web:5.1.6.RELEASE -> 5.1.7.RELEASE (*)
+--- org.springframework.boot:spring-boot-starter-web -> 2.1.5.RELEASE
| +--- org.springframework.boot:spring-boot-starter:2.1.5.RELEASE (*)
| +--- org.springframework.boot:spring-boot-starter-json:2.1.5.RELEASE
| | +--- org.springframework.boot:spring-boot-starter:2.1.5.RELEASE (*)
| | +--- org.springframework:spring-web:5.1.7.RELEASE (*)
| | +--- com.fasterxml.jackson.core:jackson-databind:2.9.8 (*)
| | +--- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.9.8
| | | +--- com.fasterxml.jackson.core:jackson-core:2.9.8
| | | \--- com.fasterxml.jackson.core:jackson-databind:2.9.8 (*)
| | +--- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.8
| | | +--- com.fasterxml.jackson.core:jackson-annotations:2.9.0
| | | +--- com.fasterxml.jackson.core:jackson-core:2.9.8
| | | \--- com.fasterxml.jackson.core:jackson-databind:2.9.8 (*)
| | \--- com.fasterxml.jackson.module:jackson-module-parameter-names:2.9.8
| | +--- com.fasterxml.jackson.core:jackson-core:2.9.8
| | \--- com.fasterxml.jackson.core:jackson-databind:2.9.8 (*)
| +--- org.hibernate.validator:hibernate-validator:6.0.16.Final (*)
| +--- org.springframework:spring-web:5.1.7.RELEASE (*)
| \--- org.springframework:spring-webmvc:5.1.7.RELEASE
| +--- org.springframework:spring-aop:5.1.7.RELEASE (*)
| +--- org.springframework:spring-beans:5.1.7.RELEASE (*)
| +--- org.springframework:spring-context:5.1.7.RELEASE (*)
| +--- org.springframework:spring-core:5.1.7.RELEASE (*)
| +--- org.springframework:spring-expression:5.1.7.RELEASE (*)
| \--- org.springframework:spring-web:5.1.7.RELEASE (*)
+--- org.springframework.boot:spring-boot-starter-aop -> 2.1.5.RELEASE
| +--- org.springframework.boot:spring-boot-starter:2.1.5.RELEASE (*)
| +--- org.springframework:spring-aop:5.1.7.RELEASE (*)
| \--- org.aspectj:aspectjweaver:1.9.4
+--- org.springframework.cloud:spring-cloud-config-client -> 2.1.1.RELEASE (*)
+--- org.springframework.cloud:spring-cloud-starter-netflix-eureka-client -> 2.1.1.RELEASE
| +--- org.springframework.cloud:spring-cloud-starter:2.1.1.RELEASE
| | +--- org.springframework.boot:spring-boot-starter:2.1.3.RELEASE -> 2.1.5.RELEASE (*)
| | +--- org.springframework.cloud:spring-cloud-context:2.1.1.RELEASE (*)
| | +--- org.springframework.cloud:spring-cloud-commons:2.1.1.RELEASE (*)
| | \--- org.springframework.security:spring-security-rsa:1.0.7.RELEASE
| | \--- org.bouncycastle:bcpkix-jdk15on:1.60
| | \--- org.bouncycastle:bcprov-jdk15on:1.60
| +--- org.springframework.cloud:spring-cloud-netflix-hystrix:2.1.1.RELEASE
| | +--- org.springframework.boot:spring-boot-autoconfigure:2.1.3.RELEASE -> 2.1.5.RELEASE (*)
| | \--- org.springframework.boot:spring-boot-starter-aop:2.1.3.RELEASE -> 2.1.5.RELEASE (*)
| +--- org.springframework.cloud:spring-cloud-netflix-eureka-client:2.1.1.RELEASE
| | \--- org.springframework.cloud:spring-cloud-netflix-hystrix:2.1.1.RELEASE (*)
| +--- com.netflix.eureka:eureka-client:1.9.8
| +--- com.netflix.eureka:eureka-core:1.9.8
| +--- org.springframework.cloud:spring-cloud-starter-netflix-archaius:2.1.1.RELEASE
| | +--- org.springframework.cloud:spring-cloud-starter:2.1.1.RELEASE (*)
| | +--- org.springframework.cloud:spring-cloud-netflix-ribbon:2.1.1.RELEASE
| | | \--- org.springframework.cloud:spring-cloud-netflix-archaius:2.1.1.RELEASE
| | +--- org.springframework.cloud:spring-cloud-netflix-archaius:2.1.1.RELEASE
| | +--- com.netflix.archaius:archaius-core:0.7.6
| | \--- commons-configuration:commons-configuration:1.8
| | \--- commons-lang:commons-lang:2.6
| +--- org.springframework.cloud:spring-cloud-starter-netflix-ribbon:2.1.1.RELEASE
| | +--- org.springframework.cloud:spring-cloud-starter:2.1.1.RELEASE (*)
| | +--- org.springframework.cloud:spring-cloud-netflix-ribbon:2.1.1.RELEASE (*)
| | +--- org.springframework.cloud:spring-cloud-starter-netflix-archaius:2.1.1.RELEASE (*)
| | +--- com.netflix.ribbon:ribbon:2.3.0
| | +--- com.netflix.ribbon:ribbon-core:2.3.0
| | +--- com.netflix.ribbon:ribbon-httpclient:2.3.0
| | +--- com.netflix.ribbon:ribbon-loadbalancer:2.3.0
| | \--- io.reactivex:rxjava:1.2.0
| +--- com.netflix.ribbon:ribbon-eureka:2.3.0
| \--- com.thoughtworks.xstream:xstream:1.4.10
| +--- xmlpull:xmlpull:1.1.3.1
| \--- xpp3:xpp3_min:1.1.4c
+--- org.springframework.cloud:spring-cloud-aws-autoconfigure -> 2.1.1.RELEASE
| +--- org.springframework.cloud:spring-cloud-aws-context:2.1.1.RELEASE
| | +--- org.springframework.cloud:spring-cloud-aws-core:2.1.1.RELEASE
| | | +--- org.springframework:spring-beans:5.1.5.RELEASE -> 5.1.7.RELEASE (*)
| | | +--- org.springframework:spring-aop:5.1.5.RELEASE -> 5.1.7.RELEASE (*)
| | | +--- com.amazonaws:aws-java-sdk-core:1.11.415 (*)
| | | +--- com.amazonaws:aws-java-sdk-s3:1.11.415 (*)
| | | +--- com.amazonaws:aws-java-sdk-ec2:1.11.415
| | | | +--- com.amazonaws:aws-java-sdk-core:1.11.415 (*)
| | | | \--- com.amazonaws:jmespath-java:1.11.415 (*)
| | | +--- com.amazonaws:aws-java-sdk-cloudformation:1.11.415
| | | | +--- com.amazonaws:aws-java-sdk-core:1.11.415 (*)
| | | | \--- com.amazonaws:jmespath-java:1.11.415 (*)
| | | \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.26
| | +--- org.springframework:spring-context:5.1.5.RELEASE -> 5.1.7.RELEASE (*)
| | \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.26
| +--- org.springframework.boot:spring-boot-autoconfigure:2.1.3.RELEASE -> 2.1.5.RELEASE (*)
| \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.26
\--- org.springframework.cloud:spring-cloud-starter-aws -> 2.1.1.RELEASE
+--- org.springframework.cloud:spring-cloud-aws-context:2.1.1.RELEASE (*)
+--- org.springframework.cloud:spring-cloud-aws-autoconfigure:2.1.1.RELEASE (*)
\--- org.slf4j:slf4j-api:1.7.25 -> 1.7.26
This is multi-project and it uses spring and spring-boot simultaneously.
It looks like I have dependencies overlapping from spring and spring boot because some projects use Spring, for example, to build a Rest API and some use Spring Boot for command-line applications.
That happens because you have already spring-cloud-aws-autoconfigure jar on classpath which contains spring.facories which loads automatically AWS related beans (autoconfiguration). When you use in your project annotation #EnableContextInstanceData it underneath causes loading the same configuration second time.

Connect Four winning combinations check works for most cases, but doesn't for certain ones

So, I basically kept a log of all the test cases I made. Fortunately, most of them work (especially for vertical win check), but sometimes it says there's a winner even when there are not four connected pieces.
(This is what I am doing for a personal project, not a school assignment.)
#include <cstdio>
#include <cstring>
#include <cstdlib>
const int stSize = 6;
const int width = 7;
class myStack // class for myStack. Each column is a stack.
{
private:
int boardArr[width][stSize];
int inUseA;
int inUseB;
int inUseC;
int inUseD;
int inUseE;
int inUseF;
int inUseG;
int moveNumber;
int slotsLeft;
//char player;
public:
myStack ()
{
for(int p = 0; p<width;p++) {
for(int c = 0; c<stSize;c++){
boardArr[p][c] = 'O';
}
}
inUseA = -1;
inUseB = -1;
inUseC = -1;
inUseD = -1;
inUseE = -1;
inUseF = -1;
inUseG = -1;
moveNumber = 0;
slotsLeft = 42;
}
int getstSize() {
return stSize;
}
int getMoveNumber() {
return moveNumber;
}
int getSlotsLeft() {
return slotsLeft;
}
void showBoard() {
printf(" =============================\n");
printf("1:| %c | %c | %c | %c | %c | %c | %c |\n",boardArr[0][5],boardArr[1][5],boardArr[2][5],boardArr[3][5], boardArr[4][5],boardArr[5][5],boardArr[6][5]);
printf("2:| %c | %c | %c | %c | %c | %c | %c |\n",boardArr[0][4],boardArr[1][4],boardArr[2][4],boardArr[3][4], boardArr[4][4],boardArr[5][4],boardArr[6][4]);
printf("3:| %c | %c | %c | %c | %c | %c | %c |\n",boardArr[0][3],boardArr[1][3],boardArr[2][3],boardArr[3][3], boardArr[4][3],boardArr[5][3],boardArr[6][3]);
printf("4:| %c | %c | %c | %c | %c | %c | %c |\n",boardArr[0][2],boardArr[1][2],boardArr[2][2],boardArr[3][2], boardArr[4][2],boardArr[5][2],boardArr[6][2]);
printf("5:| %c | %c | %c | %c | %c | %c | %c |\n",boardArr[0][1],boardArr[1][1],boardArr[2][1],boardArr[3][1], boardArr[4][1],boardArr[5][1],boardArr[6][1]);
printf("6:| %c | %c | %c | %c | %c | %c | %c |\n",boardArr[0][0],boardArr[1][0],boardArr[2][0],boardArr[3][0], boardArr[4][0],boardArr[5][0],boardArr[6][0]);
printf(" =============================\n"); // FORMAT: ([WIDTH][HEIGHT])
printf(" A B C D E F G \n");
}
void pushA() {
char data;
if (moveNumber % 2 != 0) {
data = '#';
}
else {
data = '#';
}
if (inUseA == stSize-1) {
printf("Error. Stack's full.\n");
return;
}
else {
inUseA = inUseA +1;
boardArr[0][inUseA] = data;
slotsLeft--;
moveNumber++;
}
}
void pushB() {
char data;
if (moveNumber % 2 != 0) {
data = '#';
}
else {
data = '#';
}
if (inUseB == stSize-1) {
printf("Error. Stack's full.\n");
return;
}
else {
inUseB = inUseB +1;
boardArr[1][inUseB] = data;
slotsLeft--;
moveNumber++;
}
}
void pushC() {
char data;
if (moveNumber % 2 != 0) {
data = '#';
}
else {
data = '#';
}
if (inUseC == stSize-1) {
printf("Error. Stack's full.\n");
return;
}
else {
inUseC = inUseC +1;
boardArr[2][inUseC] = data;
slotsLeft--;
moveNumber++;
}
}
void pushD() {
char data;
if (moveNumber % 2 != 0) {
data = '#';
}
else {
data = '#';
}
if (inUseD == stSize-1) {
printf("Error. Stack's full.\n");
return;
}
else {
inUseD = inUseD +1;
boardArr[3][inUseD] = data;
slotsLeft--;
moveNumber++;
}
}
void pushE() {
char data;
if (moveNumber % 2 != 0) {
data = '#';
}
else {
data = '#';
}
if (inUseE == stSize-1) {
printf("Error. Stack's full.\n");
return;
}
else {
inUseE = inUseE +1;
boardArr[4][inUseE] = data;
slotsLeft--;
moveNumber++;
}
}
void pushF() {
char data;
if (moveNumber % 2 != 0) {
data = '#';
}
else {
data = '#';
}
if (inUseF == stSize-1) {
printf("Error. Stack's full.\n");
return;
}
else {
inUseF = inUseF +1;
boardArr[5][inUseF] = data;
slotsLeft--;
moveNumber++;
}
}
void pushG() {
char data;
if (moveNumber % 2 != 0) {
data = '#';
}
else {
data = '#';
}
if (inUseG == stSize-1) {
printf("Error. Stack's full.\n");
return;
}
else {
inUseG = inUseG +1;
boardArr[6][inUseG] = data;
slotsLeft--;
moveNumber++;
}
}
int HorizontalWin() {
int horizCounter1 = 0;
int horizCounter2 = 0;
for(int n = 0; n<stSize;n++) {
for(int m = 0; m<width;m++) {
if(boardArr[n][m] == '#') {
horizCounter1++;
horizCounter2 = 0;
}
else if(boardArr[n][m] == '#') {
horizCounter2++;
horizCounter1 = 0;
}
}
if(horizCounter1 == 5 || horizCounter2 == 5) {
printf("Winner!\n");
return 1;
}
}
return 0;
}
int VerticalWin () {
int vertCounter1 = 0;
int vertCounter2 = 0;
for(int x = 0; x<width;x++) {
for(int y = 0; y<stSize;y++) {
if(boardArr[x][y] == '#') {
vertCounter1++;
vertCounter2 = 0;
}
else if(boardArr[x][y] == '#') {
vertCounter2++;
vertCounter1 = 0;
}
}
if(vertCounter1 == 4 || vertCounter2 == 4) {
printf("Winner!\n");
return 1;
}
}
return 0;
}
int diagonalWin() { // Don't mind this, i haven't started making this yet
return 0;
}
void processCommandLoop (FILE* inFile)
{
char buffer[300];
char* input;
input = fgets ( buffer, 300, inFile ); // get a line of input
// loop until all lines are read from the input
while (input != NULL)
{
// process each line of input using the strtok functions
char* command;
command = strtok (input , " \n\t");
printf ("*%s*\n", command);
if ( command == NULL ) {
printf ("Blank Line\n");
}
else if ( strcmp (command, "q") == 0){
exit(1);
}
else if ( strcmp (command, "?") == 0){
showCommands();
}
else if ( strcmp (command, "a") == 0){
pushA();
showBoard();
if (VerticalWin() == 1 || HorizontalWin() == 1) {
break;
}
}
else if ( strcmp (command, "b") == 0){
pushB();
showBoard();
if (VerticalWin() == 1 || HorizontalWin() == 1) {
break;
}
}
else if ( strcmp (command, "c") == 0){
pushC();
showBoard();
if (VerticalWin() == 1|| HorizontalWin() == 1) {
break;
}
}
else if ( strcmp (command, "d") == 0){
pushD();
showBoard();
if (VerticalWin() == 1|| HorizontalWin() == 1) {
break;
}
}
else if ( strcmp (command, "e") == 0){
pushE();
showBoard();
if (VerticalWin() == 1|| HorizontalWin() == 1) {
break;
}
}
else if ( strcmp (command, "f") == 0){
pushF();
showBoard();
if (VerticalWin() == 1|| HorizontalWin() == 1) {
break;
}
}
else if ( strcmp (command, "g") == 0){
pushG();
showBoard();
if (VerticalWin() == 1|| HorizontalWin() == 1) {
break;
}
}
else {
printf ("Invalid input: %s\n", command);
}
input = fgets ( buffer, 300, inFile ); // get the next line of input
}
}
void showCommands()
{
printf ("The commands for this game:\n");
printf("At any point, you may quit the game by entering 'q'");
printf (" q \n");
printf (" ? \n");
printf (" a \n");
printf (" b \n");
printf (" c \n");
printf (" d \n");
printf (" e \n");
printf (" f \n");
printf (" g \n");
printf("Options a-g mean that you can push a piece into the indicated stack\n");
}
};
int main()
{
FILE* inFile = stdin;
myStack test;
test.showCommands();
test.showBoard();
test.processCommandLoop(inFile);
printf("Quitting..\n");
return 1;
}
So, yes, I know I didn't write the program that efficiently (especially given that I have so many push functions xD, but my main concern is my algorithm for determining who won. My vertical case works for the most part, but my horizontal one hardly does.
To know what I mean, please take a look at my test cases:
=============================
1:| O | O | O | O | O | O | O |
2:| # | O | O | O | O | O | O |
3:| # | # | O | O | O | O | O |
4:| # | # | O | O | O | O | O |
5:| # | # | O | O | O | O | O |
6:| # | # | O | O | O | O | O |
=============================
A B C D E F G
Winner!
--
=============================
1:| # | O | O | O | O | O | O |
2:| # | O | O | O | O | O | O |
3:| # | O | O | O | O | O | O |
4:| # | # | # | O | O | O | O |
5:| # | # | # | O | O | O | O |
6:| # | # | # | O | O | O | O |
=============================
A B C D E F G
Winner!
=============================
1:| O | O | O | O | O | O | O |
2:| O | O | O | O | O | O | O |
3:| # | O | O | O | O | O | O |
4:| # | O | O | O | O | O | O |
5:| # | O | # | O | O | O | O |
6:| # | # | # | O | O | O | O |
=============================
A B C D E F G
Winner!
---------------------------------A
=============================
1:| O | O | O | O | O | O | O |
2:| O | O | O | O | O | O | O |
3:| O | # | O | O | O | O | O |
4:| O | # | O | O | O | O | O |
5:| # | # | # | O | O | O | O |
6:| # | # | # | O | O | O | O |
=============================
A B C D E F G
Winner!
=============================
1:| O | O | O | O | O | O | O |
2:| O | # | O | O | O | O | O |
3:| O | # | O | O | O | O | O |
4:| # | # | O | O | O | O | O |
5:| # | # | O | O | O | O | O |
6:| # | # | # | O | O | O | O |
=============================
A B C D E F G
Winner!
=============================
1:| # | # | O | O | O | O | O |
2:| # | # | O | O | O | O | O |
3:| # | # | O | O | O | O | O |
4:| # | # | # | O | O | O | O |
5:| # | # | # | O | O | O | O |
6:| # | # | # | O | O | O | O |
=============================
A B C D E F G
Winner!
------------------------------------B
=============================
1:| O | O | O | O | O | O | O |
2:| O | O | O | O | O | O | O |
3:| O | O | # | O | O | O | O |
4:| O | O | # | O | O | O | O |
5:| O | O | # | O | # | O | O |
6:| # | O | # | O | # | O | # |
=============================
A B C D E F G
Winner!
=============================
1:| O | O | O | O | O | O | O |
2:| O | O | # | O | O | O | O |
3:| O | O | # | O | O | O | O |
4:| O | O | # | O | O | O | O |
5:| # | O | # | # | O | O | O |
6:| # | O | # | # | O | O | O |
=============================
A B C D E F G
Winner!
=============================
1:| O | O | # | O | O | O | O |
2:| O | O | # | O | O | O | O |
3:| O | O | # | # | O | O | O |
4:| O | O | # | # | O | O | O |
5:| O | O | # | # | O | O | O |
6:| O | O | # | # | O | O | O |
=============================
A B C D E F G
Winner!
=============================
1:| O | O | O | O | O | O | O |
2:| O | O | O | O | O | O | O |
3:| O | O | O | O | O | O | O |
4:| O | O | # | O | O | O | O |
5:| # | O | # | O | O | O | O |
6:| # | O | # | # | O | # | # |
=============================
A B C D E F G
Winner!^^ shouldnt be the case.. this implies that even adjacent pieces are counted for win status.
------------------------------------C
=============================
1:| O | O | O | O | O | O | O |
2:| O | O | O | O | O | O | O |
3:| O | O | O | # | O | O | O |
4:| O | O | # | # | O | O | O |
5:| O | O | # | # | O | O | O |
6:| O | O | # | # | O | O | O |
=============================
A B C D E F G
Winner!
=============================
1:| O | O | O | # | O | O | O |
2:| O | O | O | # | O | O | O |
3:| O | O | O | # | O | O | O |
4:| O | O | O | # | O | O | O |
5:| # | O | # | # | O | O | O |
6:| # | # | # | # | O | O | # |
=============================
A B C D E F G
Winner!
=============================
1:| O | O | O | O | O | O | O |
2:| O | O | O | # | O | O | O |
3:| O | O | O | # | O | O | O |
4:| # | O | O | # | O | O | O |
5:| # | O | O | # | O | O | O |
6:| # | O | O | # | O | O | O |
=============================
A B C D E F G
Winner!
------------------------------------D
=============================
1:| O | O | O | O | O | O | O |
2:| O | O | O | O | O | O | O |
3:| O | O | O | O | # | O | O |
4:| O | O | O | O | # | O | O |
5:| # | O | O | O | # | O | O |
6:| # | O | O | O | # | O | # |
=============================
A B C D E F G
Winner!
=============================
1:| O | O | O | O | O | O | O |
2:| O | O | O | O | # | O | O |
3:| O | O | O | O | # | O | O |
4:| # | O | O | O | # | O | O |
5:| # | O | O | O | # | O | O |
6:| # | O | O | O | # | O | O |
=============================
A B C D E F G
Winner!
=============================
1:| O | O | O | O | # | O | O |
2:| O | O | O | O | # | O | O |
3:| O | O | O | O | # | O | O |
4:| O | O | O | O | # | O | O |
5:| # | O | O | # | # | O | O |
6:| # | # | O | # | # | O | # |
=============================
A B C D E F G
Winner!
------------------------------------E
=============================
1:| O | O | O | O | O | O | O |
2:| O | O | O | O | O | O | O |
3:| O | O | O | O | O | # | O |
4:| O | O | O | O | O | # | O |
5:| # | O | O | O | O | # | O |
6:| # | # | O | O | O | # | O |
=============================
A B C D E F G
Winner!
=============================
1:| O | O | O | O | O | O | O |
2:| O | O | O | O | O | # | O |
3:| O | O | O | O | O | # | O |
4:| O | O | O | O | O | # | O |
5:| # | O | O | O | O | # | O |
6:| # | # | O | O | O | # | O |
=============================
A B C D E F G
Winner!
=============================
1:| O | O | O | O | O | # | O |
2:| O | O | O | O | O | # | O |
3:| O | O | O | O | O | # | O |
4:| O | O | O | O | O | # | O |
5:| O | O | O | O | O | # | O |
6:| # | # | # | # | O | # | O |
=============================
A B C D E F G
Winner!
------------------------------------F
=============================
1:| O | O | O | O | O | O | O |
2:| O | O | O | O | O | O | O |
3:| O | O | O | O | O | O | # |
4:| O | O | O | O | O | O | # |
5:| # | O | O | O | O | O | # |
6:| # | O | # | O | O | O | # |
=============================
A B C D E F G
Winner!
=============================
1:| O | O | O | O | O | O | # |
2:| O | O | O | O | O | O | # |
3:| O | O | O | O | O | O | # |
4:| # | O | # | O | O | O | # |
5:| # | O | # | O | O | O | # |
6:| # | # | # | O | # | O | # |
=============================
A B C D E F G
Winner!
=============================
1:| O | O | O | O | O | O | O |
2:| O | O | O | O | O | O | # |
3:| O | O | O | O | O | O | # |
4:| # | O | O | O | O | O | # |
5:| # | O | O | O | # | O | # |
6:| # | # | O | O | # | O | # |
=============================
A B C D E F G
Winner!
>>>pay special attention to this error
=============================
1:| O | O | O | O | O | O | O |
2:| O | O | O | O | O | O | O |
3:| O | O | O | O | O | O | # |
4:| # | O | O | O | O | O | # |
5:| # | O | O | O | O | O | # |
6:| # | O | # | # | O | O | # |
=============================
A B C D E F G
Winner! < shouldnt be the case
------------------------------------G
horizontal error:
=============================
1:| O | O | O | O | O | O | O |
2:| O | O | O | O | O | O | O |
3:| O | O | O | O | O | O | O |
4:| O | O | O | O | O | O | O |
5:| O | O | O | O | # | O | O |
6:| # | # | # | O | # | O | O |
=============================
A B C D E F G
Winner!< shouldnt be the case
As you can see, most of the vertical cases did work, but I see a few errors here and there.
Also, my horizontal check is HARDLY working.
So, fellow CS people, where do you think I need to tweak the algorithm?
The reason why I put verticalCounter1=0 when vertcounter2 is incremented is that if a blue piece is top of a red piece on column X, then that would affect the counter of the red piece so that red pieces would have to amount to 4 again.
I tried debugging this manually with all those cases, but I am not sure how to use the GDB for cases like this. I know how to use it for segmentation faults and memory leaks, but I am new to CPP, so I apologize if I goofed up here. I tried my best.
I see a couple of problems:
You aren't resetting the counters to 0 when you hit a blank space. Both counters should reset if you encounter a position with nothing in it. This doesn't cause a problem for the vertical case because there aren't blank spaces between occupied spaces, but it is a problem for the other win types
You aren't reseting the counter when you move to a new row/column/diagonal. For example, in the HorizontalWin, When you finish checking the first row, you should reset the counter before you move on to the second row, because all four pieces need to be in the same row.

How to print a 6* 6 grid as described below in Python

How can i print a grid as shown below without any contents:
I tried the below input:
grid = [["|" for x in range(7)] for y in range(6)]
for row in grid:
print(" ".join(row))
But it generated the below output:
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
I can't think of how to connect the empty spaces with _. Any help would be appreciated.
try below code:
grid = [[" _" for x in range(6)]]
for y in range(6):
list1 = []
for x in range(13):
if x%2 == 0:
list1.append("|")
else:
list1.append("_")
grid.append(list1)
for row in grid:
print("".join(row))
output:
_ _ _ _ _ _
|_|_|_|_|_|_|
|_|_|_|_|_|_|
|_|_|_|_|_|_|
|_|_|_|_|_|_|
|_|_|_|_|_|_|
|_|_|_|_|_|_|

How to get minimum count rectangles that covers another pile of rectangle?

Assume I have a pile of rectangles, some of which intersect, some isolate. E. g.
+--------------- + +-------- +
| | | |
| | | |
| A | | C |
| +---------------- + | |
| | | | +---------+-------- +
| | | | | |
+---------|----- + B | | D |
| | | |
| | +------------------ +
+---------------- +
+------------------ + +-------- +
| | | |
| E | | X |
+-------------------+ | |
| | +-------- +
| | +------------ +
| | | |
| F | | |
| | | Y |
| | | |
+-------------------+ +------------ +
Rect A, B intersect with each other, C, D have one same point, E, F have two same points, X, Y are isolated.
I have two questions:
How to partion these rectangles into rectangles which cover A, B, C, D, E, F, X, Y exactly also have minimum count like this:
+---------+----- + +-------- +
| | | | |
| | | | |
| | | | |
| | +--------- + | |
| | | | +---------+-------- +
| | | | | |
+---------+ | | | |
| | | | |
| | | +-------------------+
+------+----------+
+------------------ + +-------- +
| | | |
| | | |
| | | |
| | +---------+
| | +------------ +
| | | |
| | | |
| | | |
| | | |
+-------------------+ +-------------+
How to cover intersected rectangles with big ones? Like this:
+---------------------------+ +-------------------+
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | +-------------------+
+---------------------------+
+-------------------+ +---------+
| | | |
| | | |
| | | |
| | +---------+
| | +------------ +
| | | |
| | | |
| | | |
| | | |
+-------------------+ +-------------+
For Q1, I've no idea at all....
For Q2, I wrote some code in C++ but have poor efficiency. I believe there're better methods/algorithm.
bool intersectRect(const Rect& rect1, const Rect& rect2) {
/* if rect1 and rect2 intersect return true
else return false
*/
}
Rect mergeIntersectRects(const set<Rect>& rects) {
// suppose rects are all intersected. This function only return a smallest Rect that cover all rects.
}
set<Rect> mergeRectToRects(const set<Rect>& rectset, const Rect& rect) {
set<Rect> _intersect_rects;
set<Rect> _unintersect_rects;
for(set<Rect>::const_iterator it = rectset.begin();
it != rectset.end();
++it) {
if(intersectRect(*it, rect))
_intersect_rects.insert(*it);
else
_unintersect_rects.insert(*it);
}
if(!_intersect_rects.empty()) {
_intersect_rects.insert(rect);
return mergeRectToRects(_unintersect_rects,
mergeIntersectRects(_intersect_rects));
}
else {
_unintersect_rects.insert(rect);
return _unintersect_rects;
}
}
First, I'm assuming that your rectangles are all axis-aligned.
For Q1, one option would be to sweep the plane while maintaining a list of line segments along the sweep line that lie in the interior of the rectangles. As you discover each rectangle vertex during the sweep you can check to see if it modifies the current interior segments and if so, start or end a rectangle as necessary.
For example, let's say your sweep line moves left to right:
Current
Interior
|
+-|------------- + +-------- + *
| | | | | |
| | | | | |
| | A | | C | |
| | +---------------- + | | |
| | | | | +---------+-------- + |
| | | | | | | |
+-|-------|----- + B | | D | *
| | | | |
| | | +------------------ +
| +---------------- +
|
+-|---------------- + +-------- + *
| | | | | |
| | E | | X | |
| |-----------------+ | | |
| | | +-------- + |
| | | +------------ + |
| | | | | |
| | F | | | |
| | | | Y | |
| | | | | |
+-|-----------------+ +------------ + *
|
When the sweep line is in the position shown above, there are two interior segments. Namely, that inside A and that inside (E U F). When the sweep line reaches the leftmost edge of B, we output a rectangle for the portion of A lying to the left. We then replace the interior of A in the segment list with the interior of (A U B).
Current
Interior
|
+---------+-|--- + +-------- + *
| | | | | | |
| | | | | | |
| | | | | C | |
| | |-------------- + | | |
| | | | | +---------+-------- + |
| | | | | | | |
+---------+ |--- + B | | D | |
| | | | | |
| | | +------------------ + |
+-|-------------- + *
|
+-----------|------ + +-------- + *
| | | | | |
| | | | X | |
| |-------+ | | |
| | | +-------- + |
| | | +------------ + |
| | | | | |
| | | | | |
| | | | Y | |
| | | | | |
+-----------|-------+ +------------ + *
|
For Q2, the answer could be computed during the same sweep by keeping track of the x-coordinate at which a segment was first added to the list (e.g. "left side of A") as well as the min and max y-coordinates that it spans during its lifetime (e.g. bottom of B to top of A). When the segment is finally removed from the list (e.g. "right side of B"), then output a rectangle using these four coordinates.
Sorting the rectangle vertices lexicographically in a preprocessing step would be O(n * log n). Processing them would be O(log n) since you can do a binary search on the known interior ranges. The total runtime should be O(n * log n).
Q1: this is called partition of rectilinear polygon. Answer from Rob's comment has very good description. I found paper mentioned in the answer useful.
Q2: I suppose that you don't want two covers of non-intersecting regions to intersect. Like cover for 3 rectangle, 2 rectangle producing L and rectangle intersection cover of L but not any L rectangle.
If it is like that, than it is possible to incrementally create covers. Here is a simple algorithm for it.
covers = {A}
for each rectangle R
while there is a cover that intersects R, say C
remove C from covers and set R = cover of R and C
add R to covers
This code is not efficient in standard form. With good structure for covers structure, it can be efficient.
Here's the algorithm: http://goo.gl/aWDJo
You can read about finding the convex hull algorithms: http://ralph.cs.cf.ac.uk/papers/Geometry/boxing.pdf
I'd use the method suggested by #Damon but speed up neighbouring rectangle search with some spatial indexing structure, for example a quadtree or a grid. You'd need two of them, first built over the set of input rectangles, to search for intersecting rectangles to split, and second built over the set of split rectangles obtained in first step, to search adjacent rectangles to merge. That should speed things up considerably compared to the naive approach.